permission denied error

wwrightchess

New Member
Joined
Apr 20, 2022
Messages
29
Office Version
  1. 365
Platform
  1. MacOS
I am trying to export charts as png. It works on the first instance but on the second I get permission denied with an error code of 70. tried granting access and setting application alerts to false. Macro below.

Sub Macro1
Dim myPath As String
Dim myName As String
Dim fullname As String
Dim i As Long
Dim filelist() As Variant
myPath = "/Volumes/MyPassport/parameter_studies/roughness/GlennIce_nml/outputs/"
fullname = myPath & "pictures"
ReDim filelist(0)
filelist(0) = fullname
fileAccessGranted = GrantAccessToMultipleFiles(filelist)
For i = 2 To 97
Workbooks("large_and_glaze_adjusted_clean.xlsx").Activate
myName = Cells(i, 1)
fullname = myPath & myName & "/" & myName & "_plots.xlsx"
Application.AskToUpdateLinks = False
Application.DisplayAlerts = False
Workbooks.Open filename:=fullname
Application.DisplayAlerts = True
Sheets("shape_plot").Select
fullname = myPath & "pictures/" & myName & ".png"
Application.DisplayAlerts = False
ActiveChart.Export fullname
Application.DisplayAlerts = True
ActiveWindow.Close
Next i
End Sub
 
in the immediate window I get
?fullname
/Volumes/MyPassport/parameter_studies/roughness/GlennIce_nml/outputs/pictures/AC048336.png
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
So based on your formula: fullname = myPath & myName & "/" & myName & "_plots.xlsx"...
does the folder "/Volumes/MyPassport/parameter_studies/roughness/GlennIce_nml/outputs/AC048336/" exist? Perhaps the folder needs to be created first?
Essentially your formula is generating /Volumes/MyPassport/parameter_studies/roughness/GlennIce_nml/outputs/AC048336/AC04336_plots.xlsx
 
Upvote 0
The folder exists and the file exists. The macro opens the workbook file it just does not export the chart sheet "shape_plot" which also exists
 
Upvote 0
I know very little about the MacOS, so grasping at straws here since we can't reproduce your problem, can you try changing your GrantAccess line to this.
VBA Code:
fileAccessGranted = GrantAccessToMultipleFiles(Array(myPath,myPath & "pictures",ThisWorkbook.path))
 
Upvote 0
Here is my fix. I do not know if there is an easier way.
First I created one png by manually exporting the chart.
Second, I duplicated the chart 96 times and gave it the name of the chart I was trying to create.
Third, I ran a macro I have that granted access to those files.
Finally, the routine I posted will run after I deleted the lines that would delete the existing file.
 
Upvote 0
Solution
As long as that works for you. It seems to be something specific to MacOS and as such I have no way of replicating it. Thanks for letting us know what you did.
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,935
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top