Private Sub cmdopendoc_Click()Dim wd As New Word.ApplicationDim strpath As StringDim pass As StringDim J, K, Pass_long As IntegerDim Max_num, Min_num, I As Longstrpath = File1.Path & "\" & File1.FileNameOn Error Resume Next'程序开始Pass_long = Val(Text2.Text)Max_num = 10 ^ Val(Text2.Text)Min_num = 10 ^ (Val(Text2.Text) - 1)Flag = 0For K = 0 To Pass_long - 1Max_num = 10 ^ (Pass_long - K)Min_num = 10 ^ (Pass_long - (K + 1))For J = 0 To Pass_long - 1cmdopendoc.MousePointer = 11For I = IIf(Pass_long - K = 1, 0, Min_num) + J To Max_num Step Pass_longText1.Text = passText1.Refreshpass = String(K, "0") & IFlag = wd.Documents.Open(FileName:=strpath, passworddocument:=pass)'如果解密成功,打开文档,显示密码,退出过程If Flag <> 0 ThenLabel1.Caption = "文档密码"Label1.RefreshText1.Text = passwd.Visible = Truecmdopendoc.MousePointer = 0Exit SubEnd IfNext INext JNext KMsgBox "密码位数不对,请重新输入"
End Sub