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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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