Image3.Picture = ThisWorkbook.Sheets("Sheet11").Shapes("Picture 2")

JNO

New Member
Joined
Feb 2, 2023
Messages
6
Office Version
  1. 365
Platform
  1. Windows
I am having difficulty with the user form reference. What I am trying to do is populate an image box with a picture saved on the current worksheet.
Code is as follows:
Private Sub CommandButton8_Click()
displayPw = InputBox("Insert the password", "INSERT SIGNATURE")
If displayPw = "DT_MATT_1" Then
Image3.Picture = ThisWorkbook.Sheets("Sheet11").Shapes("Picture 1")
End If
If displayPw = "DT_KAYLA_2" Then
Image3.Picture = ThisWorkbook.Sheets("Sheet11").Shapes("Picture 2")
End If
End Sub

User form name is "COR1"
Worksheet name is "COR_DTL"
Thank You for any help you can provide

Image3.picture is not the proper reference
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi *JNO and Welcome to the Board. Unfortunately, you can't just load a userform image control with a stored sheet picture. You need to convert the sheet picture to an image file and then load the image file to your userform image control. The easiest way to do this is to use a chart to create the image file. The following code is untested but looks like it should work for you. You never mentioned what your userform image control name is so the code uses "Image1" which you will have to change to suit. HTH. Dave
Code:
Private Sub CommandButton8_Click()
On Error GoTo ErFix
Application.ScreenUpdating = False
'make chart and temp img files
Call CreateJPG("Picture 1", "DT_MATT_1")
Call CreateJPG("Picture 2", "DT_KAYLA_2")
'load userform Image1 control '***change image name to suit
displayPw = InputBox("Insert the password", "INSERT SIGNATURE")
If displayPw = "DT_MATT_1" Then
COR1.Image1.Picture = LoadPicture(Environ$("temp") & "" & "DT_MATT_1.jpg")
End If
If displayPw = "DT_KAYLA_2" Then
COR1.Image1.Picture = LoadPicture(Environ$("temp") & "" & "DT_KAYLA_2.jpg")
End If
'removce chart and temp files
ThisWorkbook.Worksheets("Sheet11").ChartObjects _
          (ThisWorkbook.Worksheets("Sheet11").ChartObjects.Count).Delete
Kill Environ$("temp") & "" & "DT_MATT_1.jpg"
Kill Environ$("temp") & "" & "DT_KAYLA_2.jpg"
ErFix:
If Err.Number <> 0 Then
On Error GoTo 0
MsgBox "Error"
End If
Application.ScreenUpdating = True
End Sub

Sub CreateJPG(PicName As String, FileNm As String)
Dim xRgPic As Shape
'create chart and image files
ThisWorkbook.Worksheets("Sheet11").Activate
Set xRgPic = ThisWorkbook.Worksheets("Sheet11").Shapes(PicName)
xRgPic.CopyPicture
With ThisWorkbook.Worksheets("Sheet11").ChartObjects _
       (ThisWorkbook.Worksheets("Sheet11").ChartObjects.Count)
.Activate
.Chart.Paste
.Chart.Export Environ$("temp") & "" & FileNm & ".jpg", "JPG"
End With
End Sub
ps. please use code tags
 
Upvote 0
Hi *JNO and Welcome to the Board. Unfortunately, you can't just load a userform image control with a stored sheet picture. You need to convert the sheet picture to an image file and then load the image file to your userform image control. The easiest way to do this is to use a chart to create the image file. The following code is untested but looks like it should work for you. You never mentioned what your userform image control name is so the code uses "Image1" which you will have to change to suit. HTH. Dave
Code:
Private Sub CommandButton8_Click()
On Error GoTo ErFix
Application.ScreenUpdating = False
'make chart and temp img files
Call CreateJPG("Picture 1", "DT_MATT_1")
Call CreateJPG("Picture 2", "DT_KAYLA_2")
'load userform Image1 control '***change image name to suit
displayPw = InputBox("Insert the password", "INSERT SIGNATURE")
If displayPw = "DT_MATT_1" Then
COR1.Image1.Picture = LoadPicture(Environ$("temp") & "" & "DT_MATT_1.jpg")
End If
If displayPw = "DT_KAYLA_2" Then
COR1.Image1.Picture = LoadPicture(Environ$("temp") & "" & "DT_KAYLA_2.jpg")
End If
'removce chart and temp files
ThisWorkbook.Worksheets("Sheet11").ChartObjects _
          (ThisWorkbook.Worksheets("Sheet11").ChartObjects.Count).Delete
Kill Environ$("temp") & "" & "DT_MATT_1.jpg"
Kill Environ$("temp") & "" & "DT_KAYLA_2.jpg"
ErFix:
If Err.Number <> 0 Then
On Error GoTo 0
MsgBox "Error"
End If
Application.ScreenUpdating = True
End Sub

Sub CreateJPG(PicName As String, FileNm As String)
Dim xRgPic As Shape
'create chart and image files
ThisWorkbook.Worksheets("Sheet11").Activate
Set xRgPic = ThisWorkbook.Worksheets("Sheet11").Shapes(PicName)
xRgPic.CopyPicture
With ThisWorkbook.Worksheets("Sheet11").ChartObjects _
       (ThisWorkbook.Worksheets("Sheet11").ChartObjects.Count)
.Activate
.Chart.Paste
.Chart.Export Environ$("temp") & "" & FileNm & ".jpg", "JPG"
End With
End Sub
ps. please use code tags
HTH Dave
I tried the fix and got the message: Excel Error!
In an attempt to try and get pass this problem I created a blank chart "Chart 15"on the worksheet and copied the .jpg files onto the chart. there are 10 jpg files copied onto the chart all files are identified as Pictures. Just for general information these pictures are formatted pictures of signatures. My question is it possible to use the static chart created and not be required to create a temp chart. Once the project is complete no one will see the worksheet as it is password protected.

Thank you for your help on this
JNO
1675459015656.png
 
Upvote 0
Place an apostrophe in front of this line of code "On Error GoTo ErFix" and find out what line of code errors. Your picture names, sheet name, userform name and image control names have to be correct. No one will see the temp chart. Dave
 
Upvote 0
Place an apostrophe in front of this line of code "On Error GoTo ErFix" and find out what line of code errors. Your picture names, sheet name, userform name and image control names have to be correct. No one will see the temp chart. Dave
 
Upvote 0
ThisWorkbook.Worksheets("Sheet11").Activate
Where do I store the JPG Files?
JNO
Thank you again this project is very important to me.
 
Upvote 0
It errors on that line? Do you have a Sheet 11? The pic files are not stored anywhere. This code copies your pictures (Picture 1 and Picture 2) that are on Sheet 11 and uses a temp chart to create image files which can then be loaded into your userform image control. Dave
 
Upvote 0
It errors on that line? Do you have a Sheet 11? The pic files are not stored anywhere. This code copies your pictures (Picture 1 and Picture 2) that are on Sheet 11 and uses a temp chart to create image files which can then be loaded into your userform image control. Dave
Yes sheet11(COR_DTL) does exist and all of the Signatures are stored on that worksheet.
 
Upvote 0
:oops: I trialed the code and I see that I missed an important piece of code that actually makes the chart. My apologies. Dave
Replace the CreateJPG sub...
Code:
Sub CreateJPG(PicName As String, FileNm As String)
Dim xRgPic As Shape
'create chart and image files
ThisWorkbook.Worksheets("sheet11").Activate
Set xRgPic = ThisWorkbook.Worksheets("sheet11").Shapes(PicName)
xRgPic.CopyPicture
With ThisWorkbook.Worksheets("sheet11").ChartObjects.Add(COR1.Image1.Left, _
               COR1.Image1.Top,COR1.Image1.Width,COR1.Image1.Height)
End With
With ThisWorkbook.Worksheets("sheet11").ChartObjects _
       (ThisWorkbook.Worksheets("sheet11").ChartObjects.Count)
.Activate
.Chart.Paste
.Chart.Export Environ$("temp") & "" & FileNm & ".jpg", "JPG"
End With
End Sub
 
Upvote 0
:oops: I trialed the code and I see that I missed an important piece of code that actually makes the chart. My apologies. Dave
Replace the CreateJPG sub...
Code:
Sub CreateJPG(PicName As String, FileNm As String)
Dim xRgPic As Shape
'create chart and image files
ThisWorkbook.Worksheets("sheet1").Activate
Set xRgPic = ThisWorkbook.Worksheets("sheet1").Shapes(PicName)
xRgPic.CopyPicture
With ThisWorkbook.Worksheets("sheet11").ChartObjects.Add(COR1.Image1.Left, _
               COR1.Image1.Top,COR1.Image1.Width,COR1 .Image1.Height)
End With
With ThisWorkbook.Worksheets("sheet1").ChartObjects _
       (ThisWorkbook.Worksheets("sheet1").ChartObjects.Count)
.Activate
.Chart.Paste
.Chart.Export Environ$("temp") & "" & FileNm & ".jpg", "JPG"
End With
End Sub
Should the "sheet1" reference be "Sheet11" ?
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

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