Anyway, if you do not know any better, use brute force!
Source Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
' @Author - Alexander Bolte' @ChangeDate - 2013-12-15' @Description - Removes the password from a protected worksheet using brute force.' Select a protected worksheet and start the sub.SubPasswordBreaker()DimiAsInteger,jAsInteger,kAsIntegerDimlAsInteger,mAsInteger,nAsIntegerDimi1AsInteger,i2AsInteger,i3AsIntegerDimi4AsInteger,i5AsInteger,i6AsIntegerDimtrgAsWorksheetOnErrorResumeNextSettrg=ActiveSheetFori=65To66:Forj=65To66:Fork=65To66Forl=65To66:Form=65To66:Fori1=65To66Fori2=65To66:Fori3=65To66:Fori4=65To66Fori5=65To66:Fori6=65To66:Forn=32To126trg.UnprotectChr(i)&Chr(j)&Chr(k)&_Chr(l)&Chr(m)&Chr(i1)&Chr(i2)&Chr(i3)&_Chr(i4)&Chr(i5)&Chr(i6)&Chr(n)Iftrg.ProtectContents=FalseThenMsgBox"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),vbInformation,";0)"ExitSubEndIfNext:Next:Next:Next:Next:NextNext:Next:Next:Next:Next:NextEndSub
Saving an Excel workbook is a rather simple task. However you have to regard many things in IO operations, which can go wrong.
Therefore it is always good to add some extra exception handling for IO operations that are likely to fail.
Hence, although saving a workbook requires only one line of code I use below method for saving workbooks.
Source Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
' @Author - Alexander Bolte' @ChangeDate - 2014-10-26' @Description - Saving handed workbook under provided path.' @Param wrk - an initialized object of type Workbook.' @Param trgPath - a String holding the target path the handed workbook to be saved to.' @Returns - true, if the Workbook has been saved successfully, else false.' @Remarks - the workbook is handed by reference. Therefore the calling function has to take care of closing it properly after has been saved.' This function is only saving a handed workbook.PublicFunctionsaveWorkbook(ByRefwrkAsWorkbook,ByValtrgPathAsString)AsBooleanDimisSavedAsBooleanOnErrorGoToerrHandle:wrk.SaveAstrgPathisSaved=TrueerrHandle:IfErr.Number<>0ThenErr.ClearEndIfsaveWorkbook=isSavedEndFunction
In one of my projects I had to read all worksheet names from several Excel files.
Here is the code for getting all worksheet names from a closed or already opened Excel file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
' @Author - Alexander Bolte' @Change Date - 26.12.2013' @Description - Creates a list of all sheet names in workbook available under given file path.' @Param filePath - Path to Microsoft Excel file the sheet name collection should be created from.' @Returns - VBA.Collection holding all sheet names from given Microsoft Excel file.PublicFunctiongetSheetNames(ByValfilePathAsString)AsVBA.CollectionDimwrkAsWorkbookDimsheetNamesAsNewVBA.CollectionOnErrorGoToerrHandle:Setwrk=getOpenedWorkbook(filePath)IfwrkIsNothingThenSetwrk=Application.Workbooks.Open(filePath)EndIf' Get the sheet names for one file.SetsheetNames=getSheetNamesFromWorkbook(wrk)' Close workbook without saving.wrk.CloseFalseerrHandle:IfErr.Number<>0ThenErr.ClearEndIfSetwrk=NothingSetgetSheetNames=sheetNamesEndFunction