Hello everyone
I have created a form with image control and used Picture property from the properties window to load a picture to save it on the form. I would like to know what is the exact location of the embedded picture? I changes the xlsm to zip and extract the files, expecting to find media folder but with no luck. I have found `drawings` folder but with no direct access to the picture
What is the location of the picture loaded on userform
-
- PlatinumLounger
- Posts: 4967
- Joined: 31 Aug 2016, 09:02
-
- Administrator
- Posts: 79890
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: What is the location of the picture loaded on userform
The entire contents of the VBA project of the workbook, including the userform and its controls, is stored in a binary file named vbaProject.bin in the xl subfolder.
So you won't find the picture as a separate file.
So you won't find the picture as a separate file.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4967
- Joined: 31 Aug 2016, 09:02
Re: What is the location of the picture loaded on userform
this code retrieve the picture from the userform
How to change the embedded image by vba code so as to save the new one to the form?
Code: Select all
SavePicture Image1.Picture, ThisWorkbook.Path & "\MySample.bmp"
-
- Administrator
- Posts: 79890
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: What is the location of the picture loaded on userform
Sorry, I don't understand your question.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4967
- Joined: 31 Aug 2016, 09:02
Re: What is the location of the picture loaded on userform
This code may clarify my target, this is a workaround
Code: Select all
Private Sub UserForm_Initialize()
Dim ws As Worksheet, strFileName As String
Set ws = ThisWorkbook.Worksheets("Sheet1")
If ws.Range("Z1").Value = Empty Then
MsgBox "You Have To Select An Image First", vbInformation
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 "File Not Selected!"
Else
Me.Image1.Picture = LoadPicture(strFileName)
Me.Repaint
ws.Range("Z1").Value = strFileName
End If
Else
Me.Image1.Picture = LoadPicture(ws.Range("Z1").Value)
End If
End Sub
-
- Administrator
- Posts: 79890
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: What is the location of the picture loaded on userform
I don't understand what the problem is.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4967
- Joined: 31 Aug 2016, 09:02
Re: What is the location of the picture loaded on userform
What I am trying to do is the same exact manual steps to embed image into the userform, but instead of doing that manually, I need a code that loads the picture and after executing the code and closing the userform, I need to find the image that I loaded in the design view. Hope it is clear now.
-
- Administrator
- Posts: 79890
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: What is the location of the picture loaded on userform
Thanks!
Code: Select all
Sub Test()
Dim ws As Worksheet
Dim strFileName As String
Set ws = ThisWorkbook.Worksheets("Sheet1")
strFileName = ws.Range("Z1").Value
If strFileName = "" Then
MsgBox "You Have To Select An Image First", vbInformation
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")
If strFileName = "False" Then
MsgBox "File Not Selected!", vbExclamation
Exit Sub
Else
ws.Range("Z1").Value = strFileName
End If
End If
ThisWorkbook.VBProject.VBComponents("Userform1").Designer _
.Controls("Image1").Picture = LoadPicture(strFileName)
End Sub
Best wishes,
Hans
Hans
-
- Administrator
- Posts: 79890
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: What is the location of the picture loaded on userform
Don't forget to save the workbook after running this macro.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4967
- Joined: 31 Aug 2016, 09:02
Re: What is the location of the picture loaded on userform
Great my tutor.
I tried to use the code on the userform through command button like that
But I got an error which is [Object variable or With block variable not set]
I tried to use the code on the userform through command button like that
Code: Select all
Private Sub CommandButton1_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")
If strFileName = "False" Then
MsgBox "File Not Selected!", vbExclamation
Exit Sub
Else
ThisWorkbook.VBProject.VBComponents("UserForm1").Designer.Controls("Image1").Picture = LoadPicture(strFileName)
End If
End Sub
-
- Administrator
- Posts: 79890
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: What is the location of the picture loaded on userform
You want to change the design of the userform. You cannot do this while the userform is running. You have to run the macro while the userform is not open.
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4967
- Joined: 31 Aug 2016, 09:02
Re: What is the location of the picture loaded on userform
Thanks a lot for the information.
Best Regards
Best Regards