LoadPicture Save Picture does not work in userform

Ritzl

New Member
Joined
May 16, 2015
Messages
16
Hi all, :eeek:
I am new to VBA and would appreciate step by step help.
I have a userform with an image on it. What I would like is to change the pic
ture during run time. I achieved that but each time when I unload the form the old picture is back..so how can I store the new one ? And here is my code

Private Sub Label7_Click()
Dim strFileName As String

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 "No File Selected!"
Else
Me.Image8.Picture = LoadPicture(strFileName)
Image8.Height = 96
Image8.Top = 174
Image8.Width = 204
'MsgBox strFileName
'SavePicture Image, "test.bmp" ' does not work error message ????
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Me.Repaint


End If
End Sub


Thx in advance....
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
I would suggest that you store the filename somewhere (ie. cell, defined name, etc) so that it can be retrieved when needed to load the picture to the image control at run-time. Otherwise, the VBA project object model would need to be accessed, and the assignment would need to take place before the userform is loaded or shown using the Designer property...

Code:
    ThisWorkbook.VBProject.VBComponents("UserForm1").Designer.Controls("Image1").Picture = LoadPicture("C:\Users\Domenic\Pictures\sample.jpg")
    UserForm1.Show

To allow access to the VBA project object model...

Code:
Ribbon > Developer Tab > Code Group > Macro Security > Macro Settings > Developer Macro Settings

...and select/check "Trust access to the VBA project object model".

Hope this helps!
 
Upvote 0
i would suggest that you store the filename somewhere (ie. Cell, defined name, etc) so that it can be retrieved when needed to load the picture to the image control at run-time. Otherwise, the vba project object model would need to be accessed, and the assignment would need to take place before the userform is loaded or shown using the designer property...

Code:
    thisworkbook.vbproject.vbcomponents("userform1").designer.controls("image1").picture = loadpicture("c:\users\domenic\pictures\sample.jpg")
    userform1.show

to allow access to the vba project object model...

Code:
ribbon > developer tab > code group > macro security > macro settings > developer macro settings

...and select/check "trust access to the vba project object model".

Hope this helps!



thank you very much !
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top