gpt4 book ai didi

vba - 使用 VBA 打开受密码保护的工作簿

转载 作者:行者123 更新时间:2023-12-04 21:08:13 24 4
gpt4 key购买 nike

我有 wb1 和 wb2。 wb1 用于数据输入,wb2 用于记录该数据。 wb2 受密码保护(假设使用“密码”)。

下面的 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

最佳答案

打开时wb2将您的“密码”参数作为 Password 传递范围:

Set wb2 = Workbooks.Open(Filename:="C:\Users...", Password:="password")

Workbooks.Open Method (Excel)更多细节。

关于vba - 使用 VBA 打开受密码保护的工作簿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34074526/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com