excel vb怎么密码不起作用
发布网友
发布时间:2022-05-08 10:49
我来回答
共1个回答
热心网友
时间:2023-12-30 19:18
Private isFirstFlag As Boolean
Private Sub Command1_Click()
Dim oExcel, szPass
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = False
isFirstFlag = True
On Error Resume Next
zPass = ""
OpenWorkBook: Err.Clear
oExcel.Workbooks.Open "d:\test.xls", , , , szPass
If Err.Number = 1004 Then
If MsgBox(IIf(isFirstFlag, "该工作簿密码保护,是否输入密码", "密码错误,是否重新输入密码"), vbOKCancel) = vbOK Then
szPass = InputBox("请输入密码")
isFirstFlag = False
GoTo OpenWorkBook
Else
oExcel.quit
Set oExcel = Nothing
End If
Else
MsgBox "打开成功"
End If
End Sub