VBA script doesn't work in MacOS

I have a script in Windows Excel that runs perfectly, capturing a cell range and saving that as a png to a folder. However, when I run on Mac, it seems to finish but there is no image anywhere to be found. I have changed the path to accommodate a Mac, however, it doesn't work.


is the correct path format?


myPath= "Macintosh HD:users:username:Desktop:DestinationFolder:"


I do a step through and the image shows up then deletes as it should but the pic is not in the destination folder. Curious if it has anything to do with the iCloud? If I look at the path of desktop or any folder it is on iCloud.


Sub save_range_as_image()


Dim ws As Worksheet

Dim table As Range

Dim pic As Picture

Dim cht As ChartObject

Dim myPath As String

Dim myPic As String

Dim myWidth As Long

Dim myHeight As Long


Set ws = ThisWorkbook.Sheets("Game.Sheet")

Set table = ws.Range("AD4:AD7")


myPath = "Macintosh HD:Users:username:Desktop:NHL24:Goal.png" -

myPic = "GoalScoredBy.png"


table.CopyPicture xlScreen, xlPicture

myWidth = table.Width

myHeight = table.Height


Set cht = ws.ChartObjects.Add(Left:=10, Top:=40, _

Width:=myWidth, Height:=myHeight)

cht.Activate


With cht.Chart

.Paste

.Export fileName:=myPath & myPic, Filtername:="png"

End With


cht.Delete

End Sub


MacBook Air (M2, 2022)

Posted on Jan 12, 2024 1:45 PM

Reply

Similar questions

2 replies

Jan 12, 2024 5:40 PM in response to MrHoffman

I would think AppleScript or Automator could perhaps do a similar action? Seems like a relatively simple task to copy a range of cells and save that as a png or jpg to a folder.


I’ve tried a few but get a bit lost in macOS context, and haven’t been able to figure it out.


I have previously use copy screen selection and save to a folder through Automator.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

VBA script doesn't work in MacOS

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.