Solved

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

Posted on 2014-12-17
4
117 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
Nick67 earned 500 total points
ID: 40505533
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
ID: 40505617
Hi Nick, thanks for your help, works perfectly.
Bunchil
0
 
LVL 1

Author Closing Comment

by:Bunchil
ID: 40505624
I appreciate your very prompt response and help.
Bunchil
0
 
LVL 26

Expert Comment

by:Nick67
ID: 40505637
No problem,
Glad to be of service

Nick67
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
: Microsoft Office Collaborate for free and online versions of Microsoft  Word, Excel, Powerpoint, OneNote, Onedrive , Email, Calendar etc. In short we can say that Microsoft office is a suite of servers, applications and services developed by  Micr…
Viewers will learn the basics about Excel 2013’s new Flash Fill feature.
Viewers will learn the basics of formula auditing in Excel 2013.

733 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