Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14

Thread: Display picture inserted in workbook to userform

  1. #1
    Join Date
    8th June 2004
    Posts
    10

    Display picture inserted in workbook to userform

    I have a code below which displays a picture on a given condition.
    VB:
    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 at 06:10. Reason: Added Code Tags

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    7th March 2003
    Location
    Essex, England
    Posts
    11,310
    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


  3. #3
    Join Date
    8th June 2004
    Posts
    10
    Just went throught that site... i prefered to use the second one.. Thanks and more power.

    Excel Video Tutorials / Excel Dashboards Reports


  4. #4
    Join Date
    9th October 2004
    Posts
    36

    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

    Excel Video Tutorials / Excel Dashboards Reports


  5. #5
    Join Date
    7th March 2003
    Location
    Essex, England
    Posts
    11,310

    Re: Display picture inserted in workbook to userform

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

    Cheers
    Andy


  6. #6
    Join Date
    9th October 2004
    Posts
    36

    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

    Excel Video Tutorials / Excel Dashboards Reports


  7. #7
    Join Date
    6th September 2004
    Location
    Australia
    Posts
    580

    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?)

    VB:
    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

    Excel Video Tutorials / Excel Dashboards Reports


  8. #8
    Join Date
    9th October 2004
    Posts
    36

    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)

    Excel Video Tutorials / Excel Dashboards Reports


  9. #9
    Join Date
    7th March 2003
    Location
    Essex, England
    Posts
    11,310

    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
    VB:
    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 at 19:51. Reason: :)

    Cheers
    Andy


  10. #10
    Join Date
    9th October 2004
    Posts
    36

    Re: Display picture inserted in workbook to userform

    Somebody has suggested this: -
    VB:
    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 at 06:15. Reason: Added Code Tags

    Excel Video Tutorials / Excel Dashboards Reports


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Possible Answers

  1. Replies: 5
    Last Post: February 12th, 2013, 18:51
  2. Inserted Picture Disappears After Losing Focus
    By Jazzua in forum EXCEL HELP
    Replies: 11
    Last Post: August 22nd, 2008, 13:19
  3. Display A Picture Based On A Cell Value
    By JF in forum EXCEL HELP
    Replies: 1
    Last Post: March 1st, 2007, 06:14
  4. Replies: 2
    Last Post: August 4th, 2006, 00:40
  5. Display userform only with parent workbook
    By rmeix in forum EXCEL HELP
    Replies: 5
    Last Post: February 18th, 2006, 07:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
porno