From MS Access, I open an Excel (.xlsx) file to apply some changes, save and upload it on Access. Everything is managed by VBA.
If the Excel file hasn't an open password encryption, VBA works perfectly.
In order to manage a Workbook encrypted with password, I have written a VBA that has many odd bugs. I give in the form the password as an input, but the password isn't read by the following code. Opening the Workbook, Excel asks me to insert the workbook password in the prompt. Then, Workbook.Unprotect doesn't unprotect the workbook that is saved with the password. As expected, Access cannot upload data from the protected Excel file.
I think should be a very easy problem to solve, but I cannot figure it out. Have you any insight to give me?
'( VBA procedure starts with variable declaration)
Set ExcelApp = CreateObject("Excel.Application")
If IsNull(Me!Password_Ins) 'Password_Ins is the input
Then
Strg_Pwd = ""
Else: Strg_Pwd = Me!Password_Ins
End If
On Error GoTo ErrorHandler
Set WorkBookObj= ExcelApp.Workbooks.Open(Percorso, False, , , Strg_Pwd) ' asks to insert the password manually
'ExcelApp.Visible = True
WorkBookObj.Unprotect Strg_Pwd 'doesn't remove the password
' (procedure continues)