Method 1 : VBA
Only work for xls files
------------------
Sub PasswordBreaker()
'Breaks worksheet password protection.
Dim i As Integer, j As Integer, k As Integer
Dim l As Integer, m As Integer, n As Integer
Dim i1 As Integer, i2 As Integer, i3 As Integer
Dim i4 As Integer, i5 As Integer, i6 As Integer
On Error Resume Next
For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
For l = 65 To 66: For m = 65 To 66: 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 n = 32 To 126
ActiveSheet.Unprotect Chr(i) & Chr(j) & Chr(k) & _
Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
If ActiveSheet.ProtectContents = False Then
MsgBox "One usable password is " & Chr(i) & Chr(j) & _
Chr(k) & Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _
Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
Exit Sub
End If
Next: Next: Next: Next: Next: Next
Next: Next: Next: Next: Next: Next
End Sub
---------------------------------------------------------
Method 2: edit file type to zip
Work for xlsx
1. Change the xlsx file to zip
2. open the zip file and unzipped the file
3. Within the unzipped file, there is an xl folder. Inside the xl folder, there is a worksheet folder. Within the folder, there are sheets .xml file which is the sheets you want to edit.
4. Open the xml file you need to edit. Find sth like below starting by < sheetprotectionxxxxxxxSHA-512xxxxxxxxx >
e.g.
<sheetProtection algorithmName="SHA-512" hashValue="GJbcCOgov82VcZvcRRA3y24wFFBLmSL/lKfSmQyGs5X4BAf8lTCE8cAw4wj/Aw4BXcl2uGC1O2bchLu46vAscw==" saltValue="Db59P9HLpN3z71NkQZ6yUw==" spinCount="100000" sheet="1" objects="1" scenarios="1"
remove the whole < > which content the "sheetprotection" words.
Save the file.
5.) zip back all the folders and files that unzipped before as zip
6.) change back the zip file name as .xlsx file
7.) Done
港股即時
Economic Calendar
Showing posts with label vba. Show all posts
Showing posts with label vba. Show all posts
Tuesday, December 19, 2017
Monday, September 11, 2017
VBA
' ------------------------------------------------------------
' 查看目前開啟excel檔案數量
Dim OpenCnt as Integer
OpenCnt = Application.Workbooks.Count
' ------------------------------------------------------------
' 依序查已開檔名 - 方法一
Dim i As Integer
For i = 1 To Workbooks.Count
MsgBox i & " " & Workbooks(i).Name
Next
' ------------------------------------------------------------
' 依序查已開檔名 - 方法二
Dim my Sheet As WorkSheet
For Each mySheet In Worksheets
MsgBox mySheet.Name
Next mySheet
' ------------------------------------------------------------
' 開啟特定檔案 - 方法一
filename = "C:\VBA\test.xls"
Workbooks.Open filename
' ------------------------------------------------------------
' 開啟特定檔案 - 方法二
Dim filename As String
filename = "C:\VBA\test.xls"
Dim sn As Object
Set sn = Excel.Application
sn.Workbooks.Open filename
' sn.Workbooks(filename).Close ' 關閉
Set sn = Nothing
' ------------------------------------------------------------
' 關閉指定檔案, 不提示訊息
Dim filename As String
filename = "Test.xls" ' 這裡只可以給短名,給全名會錯
' 假設 Test.xls 已於開啟狀態
Application.DisplayAlerts = False ' 關閉警告訊息
Workbooks(filename).Close
Application.DisplayAlerts = True ' 再打開警告訊息
' ------------------------------------------------------------
' 關閉所有開啟檔案, 但留下主視窗
Workbooks.Close
' ------------------------------------------------------------
' 關閉 excel 程式
Application.Quit
' ------------------------------------------------------------
' 直接進行存檔
Dim filename As String
filename = "a.xls" ' 只可為短檔名
WorkBooks(filename).Save
' ------------------------------------------------------------
' 指定檔名進行另存新檔,並關閉
' 假設要將 "a.xls" 存成 "C:\b.xls"
Application.DisplayAlerts = False ' 關閉警告訊息
Workbooks("a.xls").SaveAs "C:\b.xls" ' 另存新檔
Workbooks("b.xls").Close ' 關閉 b.xls
Application.DisplayAlerts = True ' 開啟警告訊息
' ------------------------------------------------------------
' 指定當前活頁簿
Dim Caption as String
Caption = "a.xls"
Workbooks(Caption).Activate ' 將視窗切到 a.xls
' ------------------------------------------------------------
Data Type Cheat
End with:
$ : String
% : Integer (Int32)
& : Long (Int64)
! : Single
# : Double
@ : Decimal
Start with:
&H : Hex
&O : Octal
' ------------------------------------------------------------
' 查看目前開啟excel檔案數量
Dim OpenCnt as Integer
OpenCnt = Application.Workbooks.Count
' ------------------------------------------------------------
' 依序查已開檔名 - 方法一
Dim i As Integer
For i = 1 To Workbooks.Count
MsgBox i & " " & Workbooks(i).Name
Next
' ------------------------------------------------------------
' 依序查已開檔名 - 方法二
Dim my Sheet As WorkSheet
For Each mySheet In Worksheets
MsgBox mySheet.Name
Next mySheet
' ------------------------------------------------------------
' 開啟特定檔案 - 方法一
filename = "C:\VBA\test.xls"
Workbooks.Open filename
' ------------------------------------------------------------
' 開啟特定檔案 - 方法二
Dim filename As String
filename = "C:\VBA\test.xls"
Dim sn As Object
Set sn = Excel.Application
sn.Workbooks.Open filename
' sn.Workbooks(filename).Close ' 關閉
Set sn = Nothing
' ------------------------------------------------------------
' 關閉指定檔案, 不提示訊息
Dim filename As String
filename = "Test.xls" ' 這裡只可以給短名,給全名會錯
' 假設 Test.xls 已於開啟狀態
Application.DisplayAlerts = False ' 關閉警告訊息
Workbooks(filename).Close
Application.DisplayAlerts = True ' 再打開警告訊息
' ------------------------------------------------------------
' 關閉所有開啟檔案, 但留下主視窗
Workbooks.Close
' ------------------------------------------------------------
' 關閉 excel 程式
Application.Quit
' ------------------------------------------------------------
' 直接進行存檔
Dim filename As String
filename = "a.xls" ' 只可為短檔名
WorkBooks(filename).Save
' ------------------------------------------------------------
' 指定檔名進行另存新檔,並關閉
' 假設要將 "a.xls" 存成 "C:\b.xls"
Application.DisplayAlerts = False ' 關閉警告訊息
Workbooks("a.xls").SaveAs "C:\b.xls" ' 另存新檔
Workbooks("b.xls").Close ' 關閉 b.xls
Application.DisplayAlerts = True ' 開啟警告訊息
' ------------------------------------------------------------
' 指定當前活頁簿
Dim Caption as String
Caption = "a.xls"
Workbooks(Caption).Activate ' 將視窗切到 a.xls
' ------------------------------------------------------------
Data Type Cheat
End with:
$ : String
% : Integer (Int32)
& : Long (Int64)
! : Single
# : Double
@ : Decimal
Start with:
&H : Hex
&O : Octal
' ------------------------------------------------------------
Subscribe to:
Posts (Atom)