0
我有wb1和wb2。 wb1用於數據輸入,wb2用於記錄該數據。 wb2是密碼保護的(比方說「密碼」)。使用VBA打開受密碼保護的工作簿
下面的VBA位於wb1中,並在點擊按鈕上運行。就像現在一樣,在VBA運行之前彈出一個請求wb2密碼的框。有沒有辦法使用VBA在該框中輸入「密碼」?
我對VBA相當陌生,所以我也接受其他建議。謝謝!
Sub OpenClose()
Application.ScreenUpdating = False
Dim wb1 As Workbook
Dim wb2 As Workbook
Set wb1 = ThisWorkbook
Set wb2 = Workbooks.Open("C:\Users...") 'I have taken out the rest of the file path
wb1.Activate
Sheets("Entry").Activate
Range("A1:A5").Select
Selection.Copy
wb2.Activate
Sheets("Log").Activate
Range("A1").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=True
wb2.Save
wb2.Close
Set wb1 = Nothing
Set wb2 = Nothing
MsgBox "Logged and saved."
Application.ScreenUpdating = True
End Sub
看看'WorkBook.Unprotect'方法。下面是它的MSDN:https://msdn.microsoft.com/en-us/library/office/ff196695.aspx – Taelsin
FWIW - 你可以簡單地寫'wb1.Sheets(「Entry」)。Range(「A1:A5 「).Copy wb2.Sheets(」Log「)。Range(」A1「)' –