Link to home
Start Free TrialLog in
Avatar of bbao
bbaoFlag for Australia

asked on

How to add a picture using EXcel VBA on Mac?

hi Excel folks

i am looking for the right way to tell Excel VBA a pathname and show the picture given by the pathname.

please see attached the Excel Macro file for the simple macro - click a button to show a picture.

i don't know why the picture cannot be shown though the correct pathname has been hard-coded in the macro. the same issue applies to both High Sierra and Mojave, though i did see the picture shown under Mojave for once. just once and couldn't be reproduced.

User generated image
User generated image
another issue is, for some reasons the Shapes.AddPicture method doesn't work and report runtime error "104" when LinkToFile parameter is False.when LinkToFile is True, there is no runtime error but also no picture.

can anyone light me up?

thanks,
bbao
Book2.xlsm
ASKER CERTIFIED SOLUTION
Avatar of Eoin OSullivan
Eoin OSullivan
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can try to INSERT the image with a command like the following, substituting PicName with your path.
ActiveSheet.Pictures.Insert (PicName & ".jpg")

However, there is an add in that loads pictures in a mac which may help you (for free)
Check here
http://rwsoftware.weebly.com/loadpicture-for-mac.html
Avatar of bbao

ASKER

@xtermie

thanks for your suggestion. i tried your code on my Mojave running Office 365, it still can't show the picture. see below the screenshot. i also tried below code but it does the same thing.

With ActiveSheet.Pictures.Insert("/Users/dennis/Desktop/2.jpg")
    .Left = 110
    .Top = 220
    .Width = 123
    .Height = 134
End With

Open in new window


User generated image
as indicated by the error message, i tried changing the full pathname to something not existing (such as "3.jpg") then i got below runtime error "1004".

User generated image
not the thing becomes more interesting. the error message for a correct pathname suggests the file may have been moved, renamed or deleted. the error message for a really incorrect pathname tells you a runtime error code, then the debug mode shows the line with that pathname.

User generated image
Avatar of bbao

ASKER

@Eoin

you were right. i follow your instruction and Excel did show the pictures, always!

it seems to be a bug of Excel for years, as the issue applies to a number of early version of Excel for Mac. it seems to be a flag or switch somewhere in Excel runtime...
Avatar of bbao

ASKER

sorry for accepting the solution so late. thanks heaps again for all inputs.