Announcement

Collapse
No announcement yet.

Display picture inserted in workbook to userform

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Display picture inserted in workbook to userform

    I have a code below which displays a picture on a given condition.
    Code:
    If Label3.Caption = "Y" Then 
    pic = "C:\Data\H74_.jpg" 
    Image1.Picture = LoadPicture(pic)
    Lets try it on a different approach, the picture now is inserted in the workbook. Kindly advise on how to code the program. Im having a hard time looking for an answer. Was it the clipboard thing. Kindly advise
    Last edited by Jack in the UK; November 19th, 2004, 06:10. Reason: Added Code Tags

  • #2
    Hi rExgiE,

    If you have to do it with code take a look at Stephen Bullen's code for PastePicture, in his VBA programming section. http://www.bmsltd.ie/Excel/Default.htm

    Another approach is to store the pictures in spare image controls and transfer the picture between images as needed.
    To get the pictures from the worksheet to the image control you can use the normal COPY (CTRL+C) and PASTE (CTRL+V) functions. Select the picture and copy then select the Picture property of the image control and paste.

    To transfer images just use something like,
    Image2.Picture = Image1.Picture

    Cheers
    Andy

    Comment


    • #3
      Just went throught that site... i prefered to use the second one.. Thanks and more power.

      Comment


      • #4
        Re: Display picture inserted in workbook to userform

        Re the soulution to this little problem Image2.Picture = Image1.Picture

        That works but how do you make it a variable

        i.e.
        A = 4
        B= "Image" & A & ".Picture"

        Image2.Picture = B

        This dose not work

        Regards

        Dave

        Comment


        • #5
          Re: Display picture inserted in workbook to userform

          Try this
          Code:
          A = 4
              Image2.Picture = Controls("Image" & a).Picture

          Cheers
          Andy

          Comment


          • #6
            Re: Display picture inserted in workbook to userform

            Andy that works great

            Now is there any way of pointing my Image2.Picture to an EMBED("Forms.Image.1","") on a sheet

            This is where you add an image to a worksheet using the Control Tool Box.

            My aim is that I have a number of images on a sheet of which one will appear on a userform in VBA depending on a variable.

            Re Dave

            Comment


            • #7
              Re: Display picture inserted in workbook to userform

              Do you have to have the pictures on a sheet? the following code works for jpg files in a directory. The picture in this case is displayed on a chart area but you should be able to modify it for a picture box or whatever is needed (hopefully?)

              Code:
              Private Sub ComboBox1_Change()
              If Sheet1.ComboBox1.Value <> "" Then
                      ActiveSheet.ChartObjects(1).Chart.ChartArea.Fill.UserPicture PictureFile:="C:\wmdbase\pics\chem\" & ComboBox1.Value & ".jpg"
                      ActiveSheet.ChartObjects(2).Chart.ChartArea.Fill.UserPicture PictureFile:="C:\wmdbase\pics\signs\" & Range("$A$58") & ".jpg"
                      ActiveSheet.ChartObjects(3).Chart.ChartArea.Fill.UserPicture PictureFile:="C:\wmdbase\pics\signs\" & Range("$B$58") & ".jpg"
                      ActiveSheet.ChartObjects(4).Chart.ChartArea.Fill.UserPicture PictureFile:="C:\wmdbase\pics\signs\" & Range("$C$58") & ".jpg"
                  Else
                      ActiveSheet.ChartObjects(1).Chart.ChartArea.Interior.ColorIndex = xlAutomatic
                      ActiveSheet.ChartObjects(2).Chart.ChartArea.Interior.ColorIndex = xlAutomatic
                      ActiveSheet.ChartObjects(3).Chart.ChartArea.Interior.ColorIndex = xlAutomatic
                      ActiveSheet.ChartObjects(4).Chart.ChartArea.Interior.ColorIndex = xlAutomatic
              End If
              End Sub
              Justin

              Comment


              • #8
                Re: Display picture inserted in workbook to userform

                Yes I rather they were on a sheet so that non VBA people can update the images.

                I can load them off HDD using the .picture = loadfile(filename) methode.

                But I want to get them from a sheet (if possible)

                Comment


                • #9
                  Re: Display picture inserted in workbook to userform

                  Hi Dave,

                  You need to use the Copy method on the embeded object then use the PastePicture code from Stephen's example to load the image.

                  Something like this
                  Code:
                      ActiveSheet.Shapes("Picture 2").CopyPicture xlScreen, xlBitmap
                      'Paste the picture from the clipboard into our image control
                      Image1.Picture = pastepicture(xlBitmap)
                  Last edited by Dave Hawley; November 17th, 2004, 19:51. Reason: :)

                  Cheers
                  Andy

                  Comment


                  • #10
                    Re: Display picture inserted in workbook to userform

                    Somebody has suggested this: -
                    Code:
                    Private Sub CommandButton1_Click()
                    Worksheets("Sheet 1").Image1.Copy
                    Me.Paste
                    End Sub
                    This seems to work, can anybody suggest a way to determine where on my form it can be placed.
                    Last edited by Jack in the UK; November 19th, 2004, 06:15. Reason: Added Code Tags

                    Comment


                    • #11
                      Re: Display picture inserted in workbook to userform

                      Hi Dave - can i kindley ask that you use code tags for any VBA posts? Just makes the post look cool and helps with how we run the board, hope you do not mind me asking, if you need some advice please refer to the 'sticky' on the forum or plase drop a U2u to myself or any of teh moderators who will be very happy to help you.

                      I have added these tags for you so you can see an example of what i mean.

                      Cheers buddy - Jack

                      Comment


                      • #12
                        Re: Display picture inserted in workbook to userform

                        No problem with the code prompt Jack,

                        I am progressing using the following:-

                        Code:
                        Private Sub CommandButton1_Click() 
                            Worksheets("Sheet 1").Image1.Copy 
                            Me.Form1.Paste 
                        End Sub
                        This allows me to paste in a specific place.

                        Now all I need to do is find out how to get an image from a sheet rather then a control box picture

                        Any idea's welcome

                        Re Dave

                        Comment


                        • #13
                          Re: Display picture inserted in workbook to userform

                          Hi Dave,

                          does my example of using a picture on a worksheet not do what you want?

                          Maybe you could post an example of the userform and the thing you are trying to get the pic from.

                          Cheers
                          Andy

                          Comment


                          • #14
                            Re: Display picture inserted in workbook to userform

                            Hi Andy

                            Have not tried it as I did not fully understands Stephen's code. I always like to understand what is happening.

                            The Me.Paste function could well do the trick from me as if you embed a Picture on a worksheet using the control toolbox, when you select a file name to point to a image that image is then embeded in the workbook, unlike using a picture on a user form where is loads that picture every time.

                            Hope that makes sense.

                            Re Dave

                            Comment

                            Working...
                            X