+ Reply to Thread
Results 1 to 11 of 11

Insert a picture from an UserForm

Hybrid View

  1. #1
    Registered User
    Join Date
    08-03-2008
    Location
    Asturias (Spain)
    Posts
    4

    Insert a picture from an UserForm

    Sorry for my bad English.
    I'm making a UserForm for a coin collection. In this UserForm I want to look for a picture, show it in the userform and then insert it into a cell of my sheet.
    ¿Can someone help me? Thanks
    Last edited by VBA Noob; 08-03-2008 at 04:03 AM.

  2. #2
    Forum Contributor
    Join Date
    07-01-2008
    Location
    Cincinnati, OH
    Posts
    150
    Hi Rachelies.

    "In this UserForm I want to look for a picture..."

    What is the source of your pictures? Are they already loaded in the userform? Will you need to browse your hard drive for a picture, load and view it in your userform, and then send it to a range?

    What have you developed to this point?

  3. #3
    Registered User
    Join Date
    08-03-2008
    Location
    Asturias (Spain)
    Posts
    4
    Quote Originally Posted by Tom Schreiner
    Hi Rachelies.

    "In this UserForm I want to look for a picture..."

    What is the source of your pictures? Are they already loaded in the userform? Will you need to browse your hard drive for a picture, load and view it in your userform, and then send it to a range?

    What have you developed to this point?
    I want to do exactly this!!!! Can someone help me to do this? Thanks

  4. #4
    Forum Contributor
    Join Date
    07-01-2008
    Location
    Cincinnati, OH
    Posts
    150
    Hi Rachelies.

    "I'm making a UserForm for a coin collection."

    Help you or do it for you? Do you have anything to post? Have you made any attempt on your own? Please post your code or at least an attachment...

  5. #5
    Registered User
    Join Date
    08-03-2008
    Location
    Asturias (Spain)
    Posts
    4
    I know how to make the buttons, save the data into the sheet, but i dont know how to make the picture, so I answer. And I will not begin to make the userform if I don´t know how to make the picure,
    I only know a few of excel, but I know much about other materies, and if I could, I would help.

  6. #6
    Forum Contributor
    Join Date
    07-01-2008
    Location
    Cincinnati, OH
    Posts
    150
    Ok. Add UserForm1 with two commandbuttons named BrowseForFile and SendPictureToRange and Image1. The picture is inserted into the same dimenions as the selected range.

    Add the following code...

    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Private Const SW_HIDE As Long = 0
    Private Const SW_SHOW As Long = 5
    
    Private LastSelectedFilePath As String
    
    Private Sub BrowseForFile_Click()
        Dim fileToOpen
        
        fileToOpen = Application.GetOpenFilename("Picture Files (*.emf; *.wmf; *.jpg; *.jpeg; *.png; *.bmp; *.dib; *.gif; *.tif; *.tiff), *.emf; *.wmf; *.jpg; *.jpeg; *.png; *.bmp; *.dib; *.gif; *.tif; *.tiff")
    
        If fileToOpen = False Then Exit Sub
        Image1.PictureSizeMode = fmPictureSizeModeStretch
        Set Image1.Picture = LoadPicture(fileToOpen)
        LastSelectedFilePath = fileToOpen
    End Sub
    
    Private Sub SendPictureToRange_Click()
        Dim r As Range
    
        ShowWindow FindWindow("ThunderDFrame", Me.Caption), SW_HIDE
        Set r = Application.InputBox("Select the range to insert your picture...", , , , , , , 8)
        ShowWindow FindWindow("ThunderDFrame", Me.Caption), SW_SHOW
        With ActiveSheet.Pictures.Insert(LastSelectedFilePath)
            .Top = r.Top
            .Left = r.Left
            .Width = r.Width
            .Height = r.Height
        End With
    End Sub

  7. #7
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523
    Check out this example on inserting pics
    Select the blue cell and pick a picture.

    The example is located from this thread
    Last edited by davesexcel; 08-03-2008 at 07:44 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1