I'm trying to export a range of cells as Image from Excel 2016 (16.13) in a Mac (High Sierra).
So far this is what i managed to put together...
Sub Export()
Dim oWs As Worksheet
Dim oRng As Range
Dim oChrtO As ChartObject
Dim lWidth As Long, lHeight As Long
'
Set oWs = ActiveSheet
Set oRng = oWs.Range("C8:I20")
'
oRng.CopyPicture xlScreen, xlPicture
lWidth = oRng.Width
lHeight = oRng.Height
'
Set oChrtO = oWs.ChartObjects.Add(Left:=0, Top:=0, Width:=lWidth, Height:=lHeight)
'
oChrtO.Activate
With oChrtO
.ShapeRange.Line.Visible = msoFalse
.Height = oRng.Height
.Width = oRng.Width
.Chart.Paste
.Chart.Export FileName:="Report.png", Filtername:="JPG"
End With
'
oChrtO.Delete
'
End Sub
I still have the following problems:
1-Automatically file is saved into /Users/MyAccount/Library/Containers/com.microsoft.Excel/Data/ and I need to save it into a specific folder on my Desktop
2-"Small cosmetic issue", left and top edge are grey (file.png)- enter image description here
Any Suggestion?
EDIT: I also tried to add:
Dim fileAccessGranted As Boolean
Dim filePermissionCandidates
'Create an array with file paths for which permissions are needed
filePermissionCandidates = Array("/Users/<MyAccount>/Desktop/")
'Request Access from User
fileAccessGranted = GrantAccessToMultipleFiles(filePermissionCandidates)
and
.Chart.Export FileName:="/Users/<MyAccount>/Desktop/Case.jpg", Filtername:="JPG"
resulting in the Error "Run-Time error '70' Permission denied".