Microsoft Excel

Ron de Bruin
Excel Automation

Microsoft MVP Program

Load picture in image control on userform


VBA LoadPicture is not working on a Mac to load the image you want at runtime in a Image control on a Userform. Maybe you can use this in your projects as a workeround.The code below will open the picture you want in Preview, see also the commented code to make a picture of a existing chart in your workbook and show it in preview.

Change the path/file name in Filestr to yours before you test the code.

Sub ShowPictureInPreview()
'Show picture in Preview instead of a Image control
    Dim Filestr As String
    Dim scriptToRun As String
    Dim currentchart As Chart

    Filestr = "Macintosh HD:Users:YourUserName:Desktop:Ron.png"

    'Example to show picture of Chart in Preview
    ' Set currentchart = Sheets("Sheet1").ChartObjects(1).Chart
    ' currentchart.Export Filename:=Filestr, FilterName:="png"

    scriptToRun = scriptToRun & "tell application " & Chr(34) & "Finder" & Chr(34) & Chr(13)
    scriptToRun = scriptToRun & "open file " & Chr(34) & Filestr & Chr(34) & Chr(13)
    scriptToRun = scriptToRun & "end tell"

    On Error Resume Next
    MacScript (scriptToRun)
    On Error GoTo 0

End Sub

Manual :

In Excel 2011 it is not possible to load a 24 or 32 bit bmp picture manual in a image control on a Userform.
This is a bug in Excel 2011, convert your picture to a 256-color (8-bit) BMP and it will work.
Use the Picture property in the properties of the Image control to select the bmp picture you want.

Note : PictureSizeMode is not fill the image control on the Mac
You can use the picture property of a label instead, the picture will fill the label then.
You need to ensure that the label’s aspect ratio matches the picture’s aspect ratio.