Mac Office 2015下的VBA运行时错误70

时间:2017-01-17 23:33:25

标签: excel vba macos excel-vba excel-vba-mac

Hello Guys我有这个简单的脚本,我在我的电子表格中的2个图表上应用图表模板。显然,这在Windows 10,Mac Office 2011下运行良好,但在Mac Office 2015上则不行。

我得到一个错误,运行时错误70 - 权限被拒绝 两个文件都位于相同的文件夹中,名称是正确的。

 Sub Makro_Setup()
'
' Makro_Setup Makro
    '
' Tastenkombination: Strg+Umschalt+B
'
Worksheets("Auswertung").Activate

Dim path As String   
Dim TheOS As String

TheOS = Application.OperatingSystem

If MAC_OFFICE_VERSION >= 15 Then
MsgBox "Not Good"
Else
MsgBox "Good"
End If

path = ActiveWorkbook.path + "/Diagramm1.crtx"

MsgBox TheOS
MsgBox path

ActiveSheet.ChartObjects("Diagramm 2").Activate
ActiveChart.PlotArea.Select

' Here comes the error 70 -START
ActiveChart.ApplyChartTemplate path
' Here comes the error 70 -END

ActiveSheet.ChartObjects("Diagramm 5").Activate
ActiveChart.PlotArea.Select
ActiveChart.ApplyChartTemplate path

End Sub

也许有人可以帮助我:(

Ps。:路径是正确的:/ users /....

最诚挚的问候 弯刀

1 个答案:

答案 0 :(得分:0)

好的,最后我找到了Mac Office 2016问题的解决方案。问题是在新版本中,您无法在默认情况下访问文件。所以在我的代码中添加了以下内容:

'Declare Variables?
Dim fileAccessGranted As Boolean
Dim filePermissionCandidates

'Create an array with file paths for which permissions are needed?
filePermissionCandidates = Array(path, ActiveWorkbook.path)

'Request Access from User?
fileAccessGranted = GrantAccessToMultipleFiles(filePermissionCandidates)       
'returns true if access granted, false otherwise?

Simpy这个帖子对我帮助很大: VB Macros for Office 2016 for Mac require Permissions every time they try to access a file! Is there any way to get around this behavior?

最诚挚的问候 弯刀

PS。需要取消保护工作表!