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
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
I still have not gotten past this error. I tried naming the chart rather than using ActiveChart. It exports the chart on i=2 and gives
Run-time error '70' Permission denied the next time through the loop. I have checked and the file name the second time through is different so it is not trying to overwrite the first file
 
Upvote 0
here is the current routine

Sub Macro1()
'
' Macro1 Macro
'

'
Dim myPath As String
Dim myName As String
Dim fullname As String
Dim i As Long
Dim filelist() As Variant
Dim shapeChart As Chart
Dim mysheet As Worksheet

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
Workbooks(myName & "_plots.xlsx").Activate
Sheets("shape_plot").Select

Set shapeChart = Charts("shape_plot")
fullname = myPath & "pictures/" & myName & ".png"

On Error Resume Next
Kill fullname
On Error GoTo 0

shapeChart.Export filename:=fullname
Set shapeChart = Nothing
Application.DisplayAlerts = False
ActiveWindow.Close
Next i
End Sub
 
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: permission denied error
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
You are using quite a few different versions for the filename, which line is actually highlighted when it errors out ?
 
Upvote 0
Is your chart, a chart sheet (the whole sheet is just the chart) or an embedded chart (a chart on a normal worksheet ?
Also if you put what you have in MyPath and add to that "pictures/" in the explorer address bar does it open the folder that is supposed to ?
 
Upvote 0
It is a chart sheet. It works for i=2 and gives the permission denied error for i=3. The path is correct
 
Upvote 0
Does cell(3,1) contain any characters that are invalid for a filename?
 
Upvote 0

Forum statistics

Threads
1,216,082
Messages
6,128,706
Members
449,464
Latest member
againofsoul

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