Image place on userform by VBA code is lost when file is saved

Hi all, I have a spreadsheet with operations perfomed by VBA code on several userforms. I have code that allows a user to select a picture and place it on a user form as image1. The code works properly and users can navigate to a graphic file, select the file and the image is placed on the userfom. However when the file is saved and reopened the image is not on the form.
Can anyone tell me how to alter my code of add code so the image placed on the userformis not lost when the file is saved.

My routine is:

Private Sub CommandButton2_Click()

Dim openDialog As Office.FileDialog
Dim FName As String

Set openDialog = Application.FileDialog(msoFileDialogFilePicker)
openDialog.Filters.Add "JPEG Files", "*.jpg"

     With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = False
        .ButtonName = "Submit"
        .Title = "Select an image file"
        .Filters.Add "Image", "*.gif; *.jpg; *.jpeg", 1
        If .Show = -1 Then

            Me.Image1.PictureSizeMode = fmPictureSizeModeZoom
            Me.Image1.Picture = LoadPicture(.SelectedItems(1))


       End If
    End With
End Sub

Open in new window

Thank you for any help you can provide.
Who is Participating?
Nick67Connect With a Mentor Commented:
Me.Image1.Picture = LoadPicture(.SelectedItems(1))
So here you are dynamically loading an image to Image1.
Nothing wrong with that -- but nowhere do you save that path, and nowhere do you tell the userform to load that image from a saved location when the userform first opens.

So you need to save the value of .SelectedItems(1) to a cell some place, and in the userform initialize you need to check if there's a value there and LoadPicture from it.
BunchilAuthor Commented:
Hi Nick, thanks for your help, works perfectly.
BunchilAuthor Commented:
I appreciate your very prompt response and help.
No problem,
Glad to be of service

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.