Run-time '70': Permission denied

danjuma

Active Member
Joined
Sep 21, 2008
Messages
251
Hello. I have created to code below which is basically meant to create a separate workbook from the contents of the current worksheet the code is on, and save it to the specified directory using the date in cell B3 as part of the file name and as a .xlsx (don't want it to be a macro-enabled workbook for some other reasons). However, I keep getting "Run-time '70': Permission denied" and not sure what I am doing wrong. This is my home PC and I have all permissions on it. Thanks

VBA Code:
Private Sub SaveVS_Click()
  ActiveSheet.Unprotect Password:="mypassword"
  ActiveSheet.Copy  ' creates new workbook
 ActiveSheet.Range("A6:L29").Interior.ColorIndex = 19
 Date = ActiveSheet.Range("B3")
 ActiveSheet.Protect Password:="mypassword1"
  strFileName = "C:\Users\Kaye\Desktop\"
  ActiveWorkbook.SaveAs Filename:=Path & Date & "\Variation Sheets.xlsx"
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
You cannot use Date as a variable, change it to something else.
 
Upvote 0
You cannot use Date as a variable, change it to something else.
Hi, sorry, I actually realised this and changed it during my trying to work out what was wrong. Anyway, I have changed Date to just D, but now getting the following errors

vba code.JPG


vba code2.JPG
 
Upvote 0
What is Path meant to be?
Also what is in B3
 
Upvote 0
Do you have a folder on your desktop called 02-09-2021?
 
Upvote 0
Ok, try it like
VBA Code:
Private Sub SaveVS_Click()
  ActiveSheet.Unprotect Password:="mypassword"
  ActiveSheet.Copy  ' creates new workbook
 ActiveSheet.Range("A6:L29").Interior.ColorIndex = 19
 d = ActiveSheet.Range("B3")
 ActiveSheet.Protect Password:="mypassword1"
  strFileName = "C:\Users\Kaye\Desktop\"
  ActiveWorkbook.SaveAs strFileName & Format(d, "dd-mm-yyyy") & " Variation Sheets.xlsx", 51
End Sub
 
Upvote 0
Ok, try it like
VBA Code:
Private Sub SaveVS_Click()
  ActiveSheet.Unprotect Password:="mypassword"
  ActiveSheet.Copy  ' creates new workbook
 ActiveSheet.Range("A6:L29").Interior.ColorIndex = 19
 d = ActiveSheet.Range("B3")
 ActiveSheet.Protect Password:="mypassword1"
  strFileName = "C:\Users\Kaye\Desktop\"
  ActiveWorkbook.SaveAs strFileName & Format(d, "dd-mm-yyyy") & " Variation Sheets.xlsx", 51
End Sub

Brilliant! That works. Only issue is that instead of saving it straight away, I still get the below prompt (image below) and have to click 'Yes' to continue. If this could be avoided, that would be awesome, if not I will just have live with it :)

vba code.JPG
 
Upvote 0
Yup, just add these two lines before & after the saveas
VBA Code:
  Application.DisplayAlerts = False
  ActiveWorkbook.SaveAs strFileName & Format(d, "dd-mm-yyyy") & " Variation Sheets.xlsx", 51
  Application.DisplayAlerts = True
 
Upvote 0
Solution

Forum statistics

Threads
1,214,996
Messages
6,122,636
Members
449,092
Latest member
bsb1122

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