2017-09-15 91 views
1

尝试在Mac Excel 2016中将范围保存为jpeg图像。我运行VB代码,首先出现此错误:“运行时错误”-2147287035 (80030005)':指定的维度对当前图表类型无效。“如果我再次点击调试,然后F5,我得到这个错误:“运行时错误'70':权限被拒绝。”VBA Mac Excel 2016:图表。导出权限被拒绝错误70

从我的研究中,前者是沙箱问题或图表问题。我甚至为补丁添加了grantAccessToMultipleFiles,但没有帮助。

有问题的部分:

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

下面是完整的代码:

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 

我对在束手无策,任何想法表示赞赏。

回答

1

您的路径分隔符似乎不正确。请尝试以下操作:

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

注意,我去掉了调用GrantAccessToMultipleFiles,它似乎在我的机器上工作。

+0

看到这个职位的更多信息:https://stackoverflow.com/questions/15183416/vba-save-cell-contents-to-text-file-in-a-specific-location-on-mac – PerpetualStudent