I use the following VBA to save a new file on my desktop:
Sub Files() ActiveWorkbook.SaveCopyAs "C:\Users\" & Environ("Username") & "\Desktop\testfile.xlsm" Workbooks.Open "C:\Users\" & Environ("Username") & "\Desktop\" & "testfile.xlsm", UpdateLinks:=False MsgBox ("File saved successfully on desktop.") ThisWorkbook.Close SaveChanges = False End Sub All this works fine so far.
My original file is proteced with a password. This protection should be deleted in the new file which is created using the VBA above.
For unprotecting the file I have the following VBA:
Sub Unprotection() Dim b As Worksheet For Each b In Worksheets b.Unprotect Password:="abc" Next b End Sub However, i do not know how to enter this code into the procedure of creating the new file. I tried to go with the below code but it only runs in the original file and not in the new file I have created.
Sub Files() ActiveWorkbook.SaveCopyAs "C:\Users\" & Environ("Username") & "\Desktop\testfile.xlsm" Workbooks.Open "C:\Users\" & Environ("Username") & "\Desktop\" & "testfile.xlsm", UpdateLinks:=False Call Unprotection MsgBox ("File saved successfully on desktop.") ThisWorkbook.Close SaveChanges = False End Sub Do you have any idea how to solve this issue?