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
 
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

Awesome! Thank you very very much. I am most grateful! (y)
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
You're welcome & thanks for the feedback.
 
Upvote 0
Hello. With regards to my original request which ended up with the code below as the solution (many thanks Fluff for your assistance), how can I amend the code to save the file as a pdf instead of an excel file please? I am guessing the file has to be send as print to pdf and then saved as pdf, but don't know how to code this. Many thanks.

VBA Code:
Sub SaveExcelFile()
ActiveSheet.Unprotect Password:="password"
 ActiveSheet.Copy  ' creates new workbook
 ActiveSheet.Range("A6:L29").Interior.ColorIndex = 2
 d = ActiveSheet.Range("B3")
 ActiveSheet.Protect Password:="password"
 strFileName = "C:\Users\Kaye\Desktop\”
 Application.DisplayAlerts = False
 ActiveWorkbook.SaveAs strFileName & Format(d, "dd-mm-yyyy") & " Variation Sheet.xlsx", 51
Application.DisplayAlerts = True
ActiveWorkbook.Close
End Sub
 
Upvote 0
As this is a different question, it needs a new thread. Thanks
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,322
Members
452,635
Latest member
laura12345

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