Image on userform from picture in a worksheet


CG Rosen

Hi Group,

The code below loads a chart from a worksheet into an image in a userform.
Is it at all possible to use the some approach to load a picture inserted in
worksheet into the userform image?


CG Rosén

Set CurrentChart = Sheets("Sheet1").ChartObjects(1).Chart
'Save chart as GIF
Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif"
CurrentChart.Export Filename:=Fname, FilterName:="GIF"

'Show the chart
UserForm1.Image1.Picture = LoadPicture(Fname)

Kill (ThisWorkbook.Path & Application.PathSeparator & "temp.gif")



Jacob Skaria

Hi Rosen

Use the below procedure to save the picture to a location and then load this
to image control.

Sub Macro()
Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif"
SavePictureAs "Picture 1", Fname, "GIF"
UserForm1.Image1.Picture = LoadPicture(Fname)
End Sub

Sub SavePictureAs(strPicName As String, strFile As String, strFormat As

Dim wsTemp As Worksheet, chtObj As Chart, pObj As Picture
Dim dblWidth As Double, dblHeight As Double

Set pObj = Selection
dblWidth = pObj.Width: dblHeight = pObj.Height: pObj.Copy

Application.ScreenUpdating = False

Set chtObj = Charts.Add: Set wsTemp = Sheets.Add
chtObj.Location Where:=xlLocationAsObject, Name:=wsTemp.Name

With wsTemp.ChartObjects(1)
.Top = 0
.Left = 0
.Width = dblWidth
.Height = dblHeight
.Interior.ColorIndex = 1
.Chart.Export FileName:=strFile, FilterName:=strFormat
End With

Application.DisplayAlerts = False: wsTemp.Delete
Application.DisplayAlerts = True: Application.ScreenUpdating = True

End Sub

If this post helps click Yes




If you store your pictures in an imagelist object then you can load
the picture into the userform directly without using a temporary image

The imagelist object can be part of a worksheet or it can be part of
the userform itself. In both cases the normal user won't see the
imagelist object when the design mode is switched off, respectivly
when the userform is being displayed.

Here a code snippet which uses a imagelist object that is part of a

Sub UpdatePic(i As Integer)
Dim ilist As ImageList
With ThisWorkbook
' load the picture from our imagelist
Set ilist = .Worksheets(COLORsheet).OLEObjects
With ilist.ListImages
PaletteForm.Image1.Picture = .Item(i)
End With
End With
End Sub

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question