Solved

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

Posted on 2014-12-17
4
115 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
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Excel 2010 - Cumulated text to one cell by categories 2 50
kendo spreadsheet 2 285
Excel Array formula Help 11 62
REGEXTRACT expression to extract text between brackets 8 77
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 how to maximize accessibility options in an Excel workbook for users with accessibility issues.
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.

839 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