Bellatrix461
New Member
- Joined
- Sep 7, 2020
- Messages
- 8
- Platform
- Windows
Hello,
I'm trying to create a macro that will unlock and lock a source file saved in a different folder from the file I'm running the macro. It keeps giving me an error and I'm not sure what's referring to. The error says: "<Method 'Range of object'_Global' failed>". Please see screenshot attached.
Here's the macro I created to unlock the file (same error for the lock macro):
Sub Password_Unlock()
Dim WD_Report As Workbook
Dim Password As String
Rep_Password = Range("Password")
'
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'Removes password from files
MsgBox "Macro is now running, please wait"
' Application.CommandBars("Queries and Connections").Visible _
= Not (Application.CommandBars("Queries and Connections").Visible)
Set WD_Report = Workbooks.Open(Filename:=(Environ("USERPROFILE") & "\COMPANY\FOLDER NAME\FOLDER NAME\Inputs\AutomationFile.xlsx"), Password:=Rep_Password, WriteResPassword:="")
WD_Report.SaveAs Filename:=(Environ("USERPROFILE") & "\COMPANY\FOLDER NAME\FOLDER NAME\Inputs\AutomationFile.xlsx"), Password:="", WriteResPassword:=""
' Application.DisplayAlerts = False
WD_Report.Close
Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "Finished removing password from Automation File"
End Sub
Thank you for all your help!
I'm trying to create a macro that will unlock and lock a source file saved in a different folder from the file I'm running the macro. It keeps giving me an error and I'm not sure what's referring to. The error says: "<Method 'Range of object'_Global' failed>". Please see screenshot attached.
Here's the macro I created to unlock the file (same error for the lock macro):
Sub Password_Unlock()
Dim WD_Report As Workbook
Dim Password As String
Rep_Password = Range("Password")
'
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'Removes password from files
MsgBox "Macro is now running, please wait"
' Application.CommandBars("Queries and Connections").Visible _
= Not (Application.CommandBars("Queries and Connections").Visible)
Set WD_Report = Workbooks.Open(Filename:=(Environ("USERPROFILE") & "\COMPANY\FOLDER NAME\FOLDER NAME\Inputs\AutomationFile.xlsx"), Password:=Rep_Password, WriteResPassword:="")
WD_Report.SaveAs Filename:=(Environ("USERPROFILE") & "\COMPANY\FOLDER NAME\FOLDER NAME\Inputs\AutomationFile.xlsx"), Password:="", WriteResPassword:=""
' Application.DisplayAlerts = False
WD_Report.Close
Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "Finished removing password from Automation File"
End Sub
Thank you for all your help!