1

I have a userform with a browse button that allows users to search through their drive and select a picture (for example a logo):

Private Sub BrowseButton_Click()

Dim strFileName As String

'use GetOpenFilename Method to select picture
strFileName = Application.GetOpenFilename(filefilter:="Tiff Files(*.tif;*.tiff),*.tif;*.tiff,JPEG Files (*.jpg;*.jpeg;*.jfif;*.jpe),*.jpg;*.jpeg;*.jfif;*.jpe,Bitmap Files(*.bmp),*.bmp", FilterIndex:=2, Title:="Select a File", MultiSelect:=False)

If strFileName = "False" Then
    MsgBox "File Not Selected!"
    Else
    'load picture to Image control, using LoadPicture property
    Me.Image1.Picture = LoadPicture(strFileName)
    'after any change vba has to be told to refresh the UserForm for the change to appear
    Me.Repaint
    'label caption changes after picture is loaded
    Me.Label1.Caption = "Logo loaded"
End If

End Sub

The selected picture is stored in an image box on the userform. I have a submit button that, when selected, I wish to get the "picture" that the user selected from the image box and insert it in a specific location on a sheet. This is what I have so far:

Sub Image9_Click()

'' Submit Button

Dim sld As Worksheet
Set sld = Sheets("Sliders")

Dim logo As Image
logo = colourForm.Image1

Call updateAllColScheme ''Ignore this

colourForm.Hide

End Sub

This doesn't work at all as it throws an error, does anyone know if this can be done?

3
  • In programming, "it throws an error" is not a very useful problem description. What error is raised, and on which line of your code? Commented Aug 31, 2016 at 16:48
  • You already have the image file path and name (from user input), why not use ThisWorkbook.Worksheets(3).Pictures.Insert("File Path Here")? Commented Aug 31, 2016 at 16:49
  • did you consider using SavePicture Me.ControlName.Picture, Filename , and then activesheet.pictures.insert(filename) ? Commented May 31, 2017 at 16:04

1 Answer 1

-1

It's simple

just adds a TextBox (can be invisible in userform)

Private Sub BrowseButton_Click()

Dim strFileName As String

use GetOpenFilename Method to select picture
strFileName = Application.GetOpenFilename(filefilter:="Tiff Files(*.tif;*.tiff),*.tif;*.tiff,JPEG Files (*.jpg;*.jpeg;*.jfif;*.jpe),*.jpg;*.jpeg;*.jfif;*.jpe,Bitmap Files(*.bmp),*.bmp", FilterIndex:=2, Title:="Select a File", MultiSelect:=False)

TextBox1 = strFileName  'use to save URL or Link from picture

If strFileName = "False" Then
    MsgBox "File Not Selected!"
    Else
    'load picture to Image control, using LoadPicture property
    Me.Image1.Picture = LoadPicture(strFileName)
    'after any change vba has to be told to refresh the UserForm for the change to appear
    Me.Repaint
    'label caption changes after picture is loaded
    Me.Label1.Caption = "Logo loaded"
End If

End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.