Solved

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

Posted on 2014-12-17
4
110 Views
Last Modified: 2014-12-17
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.Clear
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))
            Me.Repaint
            

       Else
            

       End If
       
    End With
End Sub

Open in new window


Thank you for any help you can provide.
Bunchil
0
Comment
Question by:Bunchil
  • 2
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
Nick67 earned 500 total points
Comment Utility
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.
0
 
LVL 1

Author Comment

by:Bunchil
Comment Utility
Hi Nick, thanks for your help, works perfectly.
Bunchil
0
 
LVL 1

Author Closing Comment

by:Bunchil
Comment Utility
I appreciate your very prompt response and help.
Bunchil
0
 
LVL 26

Expert Comment

by:Nick67
Comment Utility
No problem,
Glad to be of service

Nick67
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
Viewers will learn the basics of formula auditing in Excel 2013.
Viewers will learn a basic data manipulation technique of unpivoting data in Power Query for Excel 2013 and the importance of using good data. Start with data in a poor structure: Create a table on your data: Unpivot columns: Rename columns: …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now