2016-08-05 34 views
3

Ich möchte eine Excel-Datei öffnen, die mit einem Passwort zum Ändern mit VBScript gespeichert wird. Mein aktueller Code VBS-Code ist unten, was funktioniert, aber es taucht immer wieder auf, wenn boax nach einem Passwort fragt. Wie kann ich die Excel-Tabelle mit Excel öffnen, die mich nach einem Passwort fragt?Öffnen Sie eine Excel-Datei mit Passwort zum Ändern

Option Explicit 

On Error Resume Next 

ExcelMacroExample 

Sub ExcelMacroExample() 

    Dim xlApp 
    Dim xlBook 

    Set xlApp = CreateObject("Excel.Application") 
    Set xlBook = xlApp.Workbooks.Open("C:\Users\jasons\Documents\TestFile.xlsm",,,,"yep123") 
    xlApp.Visible = True 
    xlApp.Run "Refresh_data_ss" 
    xlApp.Save 
    xlApp.Quit 

    Set xlBook = Nothing 
    Set xlApp = Nothing 

End Sub 
+0

Es scheint zwei Passwörter zu geben, die Workbooks.open fragen könnte. Eine für den offenen und eine für den Schreibzugriff auf ein schreibgeschütztes Buch. Könnte das etwas damit zu tun haben? https://msdn.microsoft.com/en-us/library/office/ff194819.aspx –

Antwort

1

Sie können das Passwort von einem InputBox bekommen

myPass = InputBox("Write the password: ") 
Set xlBook = xlApp.Workbooks.Open("C:\Users\jasons\Documents\TestFile.xlsm",,,, myPass)