- If WScript.Arguments.Count <> 1 Then
- MsgBox "参数异常"
- WScript.Quit()
- End If
- strPath = WScript.Arguments(0)
-
- Set oExcel = CreateObject("Excel.Application")
- Set oWorkBook = oExcel.Workbooks.Open(strPath)
- For Each oSheet In oWorkBook.Sheets
- RemoveShProtect oSheet
- Next
- oWorkBook.Close False '关闭文件
- Set oWorkBook = Nothing
- oExcel.Quit()
-
- Sub RemoveShProtect(mywst)
- Dim i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, t
- On Error Resume Next
- If mywst.ProtectContents = False Then
- MsgBox mywst.Name & "该工作表没有保护密码!"
- Exit Sub
- End If
- t = Timer()
- For i1 = 65 To 66 : For i2 = 65 To 66 : For i3 = 65 To 66
- For i4 = 65 To 66 : For i5 = 65 To 66 : For i6 = 65 To 66
- For i7 = 65 To 66 : For i8 = 65 To 66 : For i9 = 65 To 66
- For i10 = 65 To 66 : For i11 = 65 To 66 : For i12 = 32 To 126
- mywst.Unprotect Chr(i1) & Chr(i2) & Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(i7) & Chr(i8) & Chr(i9) & Chr(i10) & Chr(i11) & Chr(i12)
- If mywst.ProtectContents = False Then
- MsgBox "解除工作表保护!用时" & Format(Timer() - t, "0.00") & "秒"
- Exit Sub
- End If
- Next : Next : Next : Next : Next : Next : Next : Next : Next : Next : Next : Next
- End Sub
复制代码
|