Search code examples
excelvbaruntime-error

VBA Mac Excel 2016: Chart .Export Permission Denied Error 70


Trying to save a range as a jpeg image in Mac Excel 2016. I run the VB code, and first I get this error: "Run-time error '-2147287035 (80030005)': The specified dimension is not valid for the current chart type." If I hit Debug and then F5 again, I get this error: "Run-time error '70': Permission denied."

From my research, the former is either a sandbox issue or a chart issue. I even added grantAccessToMultipleFiles for a fix, but no help.

Part with issues:

.Chart.Export Filename:=ThisWorkbook.Path & "/william.jpg", Filtername:="JPG"

Here is the full code:

Sub SaveImage()
'from stackoverflow originally
Dim sSheetName As String
Dim oRangeToCopy As Range
Dim Lastrow As Integer
Dim manager As String
manager = Worksheets("by Mgr").Range("C6").Value
Set b = Worksheets("by Mgr").Range("T:T").Find(what:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues)
Lastrow = b.Row
sSheetName = "by Mgr" ' worksheet to work on
With Worksheets(sSheetName).Range("A1:T" & Lastrow)
    .CopyPicture xlScreen, xlPicture
    'Getting the Range height
    PicHeight = .Height
    'Getting the Range Width
    PicWidth = .Width
End With
filePermissionCandidates = Array(ThisWorkbook.Path)
fileAccessGranted = GrantAccessToMultipleFiles(filePermissionCandidates)
With Worksheets(sSheetName)
    'Creating the Chart
    .ChartObjects.Add(30, 44, PicWidth, PicHeight).name = manager
    With .ChartObjects(manager)
        'Pasting the Image
        .Chart.Paste
        'Exporting the Chart
        .Chart.Export Filename:=ThisWorkbook.Path & "/william.jpg", Filtername:="JPG"
        End With
    .ChartObjects(manager).Delete

End With
End Sub

I'm about at wits end, any ideas are appreciated.


Solution

  • Your path separator appears to be incorrect. Try the following:

    .Chart.Export Filename:=ThisWorkbook.Path & Application.PathSeparator & "william.jpg", Filtername:="JPG"
    

    Note that I removed the call to GrantAccessToMultipleFiles and it appeared to work on my machine.