Zobrazují se příspěvky se štítkemexcel. Zobrazit všechny příspěvky
Zobrazují se příspěvky se štítkemexcel. Zobrazit všechny příspěvky

10. ledna 2025

Macro for LibreOffice

 LibreOffice Calc - Makra





OpravitCiselneBunkySDesetinnouTeckou

🎯 Cíl - Účel:

Bezpečně nahradit desetinné tečky za čárky a převést hodnoty zpět na čísla, ale pouze v buňkách obsahujících čistě číselné hodnoty (ať jako text, nebo číslo) v LibreOffice.

🔍 Vstupní rozsah:

List: aktuálně aktivní

Sloupce: A–Y (0–24)

Řádky: 0–1000 (lze změnit)

📋 Struktura kroků:

Analýza dat

Projde všechny buňky a spočítá ty, které obsahují: desetinnou tečku

a po nahrazení tečky čárkou dávají číselný formát (IsNumeric).

Dotaz na potvrzení akce

Pokud byly takové buňky nalezeny, zobrazí dotaz: „Nalezeno X buněk. Chceš je převést do CZ formátu?“

Převod hodnot

Nahrazuje tečku za čárku, převádí výsledek na číslo (CDbl),

ukládá jako číselnou hodnotu (setValue),

nastavuje formát na standardní číselný (NumberFormat = 0).


Závěrečné hlášení

Vypíše počet opravených buněk a název listu.

🔒 Ochrana dat:

Nezasahuje do textů obsahujících slova, znaky, jednotky, data apod.

Nepřepisuje prázdné ani nenačitatelné buňky.

🟢 Použitelné pro lokalizace, kde je čárka desetinným oddělovačem.



Makro má cca 80 řádků


 ------------ začátek Makra ------------


Sub OpravitCiselneBunkySDesetinnouTeckou()

    Dim oDoc As Object, oSheet As Object

    Dim oCell As Object

    Dim sText As String, sProKontrolu As String

    Dim dValue As Double

    Dim iRow As Long, iCol As Long

    Dim iLastRow As Long

    Dim pocetKandidatu As Long, pocetOpraveno As Long

    Dim odpoved As Integer

    Dim jmenoListu As String


    oDoc = ThisComponent

    oSheet = oDoc.CurrentController.ActiveSheet

    jmenoListu = oSheet.Name

    iLastRow = 1000


    ' Najdi počet čistě číselných buněk s tečkou

    For iRow = 0 To iLastRow

        For iCol = 0 To 24

            oCell = oSheet.getCellByPosition(iCol, iRow)


            If oCell.Type = 1 Then ' číslo

                sText = oCell.getFormula()

            ElseIf oCell.Type = 2 Then ' text

                sText = Trim(oCell.getString())

            Else

                sText = ""

            End If


            If sText <> "" And InStr(sText, ".") > 0 Then

                sProKontrolu = Replace(sText, ".", ",")

                If IsNumeric(sProKontrolu) Then

                    pocetKandidatu = pocetKandidatu + 1

                End If

            End If

        Next iCol

    Next iRow


    If pocetKandidatu = 0 Then

        MsgBox "List: " & jmenoListu & Chr(10) & _

               "Nebyly nalezeny žádné čistě číselné hodnoty s tečkou.", 64, "Konec"

        Exit Sub

    End If


    odpoved = MsgBox("List: " & jmenoListu & Chr(10) & _

                     "Nalezeno " & pocetKandidatu & " buněk s čistě číselnou hodnotou s tečkou." & Chr(10) & _

                     "Chceš je převést do CZ formátu?", 36, "Potvrď akci")

    If odpoved <> 6 Then Exit Sub


    ' Proveď převod

    For iRow = 0 To iLastRow

        For iCol = 0 To 24

            oCell = oSheet.getCellByPosition(iCol, iRow)


            If oCell.Type = 1 Then

                sText = oCell.getFormula()

            ElseIf oCell.Type = 2 Then

                sText = Trim(oCell.getString())

            Else

                sText = ""

            End If


            If sText <> "" And InStr(sText, ".") > 0 Then

                sProKontrolu = Replace(sText, ".", ",")

                If IsNumeric(sProKontrolu) Then

                    On Error Resume Next

                    dValue = CDbl(sProKontrolu)

                    If Err = 0 Then

                        oCell.NumberFormat = 0

                        oCell.setValue(dValue)

                        pocetOpraveno = pocetOpraveno + 1

                    End If

                    On Error GoTo 0

                End If

            End If

        Next iCol

    Next iRow


    MsgBox "List: " & jmenoListu & Chr(10) & _

           "Opraveno: " & pocetOpraveno & " číselných buněk.", 64, "Hotovo"

End Sub



 ------------ konec Makra ------------







--------------------------------------------------------------------------

Makro:
Vyhledat ve dvou listech a Sloučit do 3. různě umístěné řádky podle názvu země


Makro SloucitZemeDoList3Final v LibreOffice Calc 


slučuje data o zemích ze dvou listů („List_1“ a „List_2“) do třetího listu („List_3“).
Hlavním cílem je najít odpovídající země v obou seznamech, spojit jejich informace na jeden řádek a zaznamenat, zda bylo spárování úspěšné.


Podrobný popis hlavní logiky

1. Inicializace a příprava

Makro si načte tři listy: List_1, List_2, List_3 (ten vytvoří, pokud neexistuje).

Vymaže celý obsah List_3.

Zkopíruje první čtyři řádky (např. hlavičky) z obou listů do List_3, včetně barvy písma.


2. Zjištění rozsahu dat

Určí, kde končí data v List_1 (dle sloupce A) a List_2 (dle sloupce B).


3. Hlavní slučovací smyčka

Pro každý řádek od 4. dál v List_1:

Normalizuje název země (bez diakritiky, malými písmeny, ořízne mezery).

Zkopíruje data ze sloupců A–K (0–10) do List_3.

Hledá odpovídající zemi ve sloupci B v List_2, rovněž po normalizaci.

Pokud ji najde:

Zkopíruje data ze sloupců 0–5 z List_2 do sloupců 11–16 v List_3.

Označí řádek jako „OK“.

Pokud ji nenajde:

Vloží text „bez dat z tradingeconomics.com“ do sloupců 18–19.


4. Závěrečná zpráva

Po dokončení vypíše počet úspěšně spárovaných a nespárovaných řádků.



Funkce Normalize(s)

Tato pomocná funkce:

Odstraní nežádoucí znaky (neviditelné mezery, tabulátory, nové řádky),

Převede text na malá písmena,

Odstraní českou diakritiku (např. „č“ → „c“),

Slouží ke srovnání zemí bez ohledu na odlišnosti v zápisu.



MACRO má celkově 126 řádků.





 ------------ začátek Makra ------------



Sub SloucitZemeDoList3Final()


    Dim oDoc As Object

    Dim oSheet1 As Object, oSheet2 As Object, oSheet3 As Object

    Dim lastRow1 As Long, lastRow2 As Long

    Dim i As Long, j As Long, k As Long

    Dim zeme1 As String, zeme2 As String

    Dim nalezeno As Boolean

    Dim startRow As Long: startRow = 4

    Dim radek3 As Long

    Dim c1 As Object

    Dim c2 As Object


    oDoc = ThisComponent

    oSheet1 = oDoc.Sheets.getByName("List_1")

    oSheet2 = oDoc.Sheets.getByName("List_2")


    ' Vytvořit List_3 pokud neexistuje

    On Error Resume Next

    oSheet3 = oDoc.Sheets.getByName("List_3")

    If oSheet3 Is Nothing Then

        oDoc.Sheets.insertNewByName("List_3", 2)

        oSheet3 = oDoc.Sheets.getByName("List_3")

    End If

    On Error Goto 0


    ' Vymazat List_3

    oSheet3.getCellRangeByPosition(0,0, oSheet3.Columns.Count-1, oSheet3.Rows.Count-1).ClearContents(7)


    ' Přenést řádky 0–3 z obou listů

    For i = 0 To startRow - 1

        For k = 0 To 10

            c1 = oSheet1.getCellByPosition(k, i)

            With oSheet3.getCellByPosition(k, i)

                .String = c1.String

                .CharColor = c1.CharColor

            End With

        Next k

        For k = 0 To 5

            c2 = oSheet2.getCellByPosition(k, i)

            With oSheet3.getCellByPosition(11 + k, i)

                .String = c2.String

                .CharColor = c2.CharColor

            End With

        Next k

    Next i


    ' Najít konce dat

    lastRow1 = startRow

    Do While oSheet1.getCellByPosition(0, lastRow1).String <> ""

        lastRow1 = lastRow1 + 1

    Loop


    lastRow2 = startRow

    Do While oSheet2.getCellByPosition(1, lastRow2).String <> ""

        lastRow2 = lastRow2 + 1

    Loop


    radek3 = startRow


    Dim uspesne As Long: uspesne = 0

    Dim nenalezene As Long: nenalezene = 0


    For i = startRow To lastRow1 - 1

        zeme1 = Normalize(oSheet1.getCellByPosition(0, i).String)

        nalezeno = False


        ' Přenos A–K

        For k = 0 To 10

            c1 = oSheet1.getCellByPosition(k, i)

            With oSheet3.getCellByPosition(k, radek3)

                .String = c1.String

                .CharColor = c1.CharColor

            End With

        Next k


        ' Hledání v List_2

        For j = startRow To lastRow2 - 1

            zeme2 = Normalize(oSheet2.getCellByPosition(1, j).String)

            If zeme1 = zeme2 Then

                For k = 0 To 5

                    c2 = oSheet2.getCellByPosition(k, j)

                    With oSheet3.getCellByPosition(11 + k, radek3)

                        .String = c2.String

                        .CharColor = c2.CharColor

                    End With

                Next k

                nalezeno = True

                Exit For

            End If

        Next j


        If nalezeno Then

            oSheet3.getCellByPosition(18, radek3).String = "OK"

            uspesne = uspesne + 1

        Else

            oSheet3.getCellByPosition(18, radek3).String = "bez dat z"

            oSheet3.getCellByPosition(19, radek3).String = "tradingeconomics.com"

            nenalezene = nenalezene + 1

        End If


        radek3 = radek3 + 1

    Next i


    MsgBox "Přenesení do List_3 dokončeno:" & Chr(10) & _

           " - spárováno: " & uspesne & Chr(10) & _

           " - nenalezeno: " & nenalezene, 64, "Hotovo"


End Sub


Function Normalize(s As String) As String

    Dim aDiak As String, bBez As String, i As Integer, c As String

    aDiak = "áčďéěíňóřšťúůýžÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ"

    bBez  = "acdeeinorstuuyzACDEEINORSTUUYZ"

    s = Replace(s, Chr(160), " ")

    s = Replace(s, Chr(9), " ")

    s = Replace(s, Chr(10), "")

    s = Replace(s, Chr(13), "")

    s = Trim(s)

    s = LCase(s)

    For i = 1 To Len(aDiak)

        c = Mid(aDiak, i, 1)

        s = Replace(s, c, Mid(bBez, i, 1))

    Next i

    Normalize = s

End Function




 ------------ konec Makra ------------

























Cituji kousek z návodu:

Nápověda LibreOffice Basic

https://help.libreoffice.org/latest/cs/text/sbasic/shared/main0601.html?DbPAR=BASIC

Tato část nápovědy obsahuje popisy nejběžnějších funkcí LibreOffice Basic. Podrobnější informace získáte na wiki v LibreOffice BASIC Programming Guide.

Práce s LibreOffice Basic

Programování v LibreOffice Basic

Běhové funkce

Záznam makra

Vytvoření dialogového okna v aplikaci Basic ... 








excel xls xlsx odt

11. dubna 2020

Check Mark Symbols alt codes symbols



How to Insert Check Mark Symbol in Google Sheets


Check Mark Symbols   Unicode Hex

How to type a check mark symbol in Word or in Excel?

Use WingDings to display special check box controls in an Access report



Difference Between Checkmark and Checkbox



or copy and paste:  ✓ ✔ 🗸 ☑ 🗹






How to type checkmark symbol in Excel


Insert Tick Box Symbols In Google Docs









ms excel
google sheets


font symbol like checkbox


31. prosince 2018

Best Exchange rate

Best Exchange rate

Best Cloud Exchange rate




currency wise

TransferWise Competitors and Alternatives


Currencies Direct
CurrencyTransfer
InstaReM
MoneyGram
OFX
PayPal
Remit2India
RemitMoney
Ria
TransferWise
Travelex
Walmart
Western Union
WorldRemit
XE Money Transfer
Xoom


http://transferwise.com/u/pavelc29

www.roklen.cz/roklenfx/

TransferWise.com/pricing/




Jak funguje TransferWise? Princip peer-to-peer sítě

Jak funguje TransferWise? Princip peer-to-peer sítě

https://www.transfertip.cz/napoveda-pro-zasilani-penez/transferwise/

Roklen Fx   forex
www.roklen.cz/roklenfx/


https://fxloader.com/fxloader-cloud-service/

www.aboundingltd.com/live-rates/

www.themoneycloud.com/money-transfers-czk-eur-receive-10000.00






ČNB - kurzy devizového trhu
www.cnb.cz/cs/casto-kladene-dotazy/Kurzy-devizoveho-trhu-na-www-strankach-CNB/


  • HTML formát
URL pro přístup: 
www.cnb.cz/cs/financni-trhy/devizovy-trh/kurzy-devizoveho-trhu/kurzy-devizoveho-trhu/index.html?date=DD.MM.RRRR

DD - den
MM - měsíc
RRRR - rok
  • TXT formát
URL pro přístup: 
www.cnb.cz/cs/financni-trhy/devizovy-trh/kurzy-devizoveho-trhu/kurzy-devizoveho-trhu/denni_kurz.txt?date=DD.MM.RRRR

nebo 
www.cnb.cz/cs/financni-trhy/devizovy-trh/kurzy-devizoveho-trhu/kurzy-devizoveho-trhu/denni_kurz.txt
(bez parametru, pouze pro aktuální devizové kurzy)

DD - den
MM - měsíc
RRRR - rok
Popis TXT formátu:





CZK-EUR
www.kurzy.cz/kurzy-men/grafy/CZK-EUR/




mám

Best places to exchange currency in Prague
https://transferwise.com/gb/blog/currency-exchange-prague

www.currencytransfer.com


www.finder.com/world-first-vs-transferwise?country_from=CZE&country_to=EUR&amount=250000

www.icomparefx.com/compare-transferwise-with-xe-money-transfer/






kurzy měn
měna
euro
czk
eur
usd
gbp


28. února 2017

Google Spreadsheets TEXT WEEKDAY

Google Spreadsheets  TEXT WEEKDAY



Excel WEEKDAY Function

Countif by weekday

Returning the day of the week as text not as a number


Google Sheets Functions – WEEKDAY, WORKDAY, NETWORKDAYS, EDATE, EOMONTH


What day of the week was a particular date?

Find out the date a number of days from a given date

How many working days are there between two dates?

Easily adding start of the month and end of the month dates

https://www.bazroberts.com/category/sheet-functions/



Date and time expressions

Apps using Dates, Times, and DateTimes



Entering Dates with the DATE Function in Google Spreadsheets

Google Spreadsheet IF Function
Using the IF Statement in Google Spreadsheets

How to Use the AND and OR Functions in Google Spreadsheets

Test Multiple Conditions with Google Spreadsheets' AND and OR Functions






Anyone knows wheter the TEXT formula works so =TEXT(WEEKDAY(     ,),"DDD") works in Google Spreadsheets?  Currently it doesn't return Mon, Tue, etc.

This works in Microsoft Excel;
                                 A                                            B
1        =TEXT(WEEKDAY(B1,1),"DDD")  
            2/25/2009
2        =TEXT(WEEKDAY(B2,1),"DDD")                2/26/2009


A1 will show "Wed", A2 shows "Thu".

----------------

Try:
A1: =MID( TEXT(WEEKDAY(B1,1),"yyEEE");3;3)
or just
A1: =MID( TEXT(B2,"yyEEE");3;3)

----------------

Try:
A1: =MID( TEXT(WEEKDAY(B1,1),"yyEEE");3;3)
or just
A1: =MID( TEXT(B2,"yyEEE");3;3)




You may also be interested in the spreadsheet referenced below:

text format string - date and time patterns - numbers



https://productforums.google.com/forum/#!topic/docs/SxnD0CgW_fY

Linking Sheets to Automatically Update




Get The Weekday Name From A Date  -  http://googledocstips.com




WEEKDAY

https://support.google.com/docs/answer/3092985?hl=en


Get day name from date

TEXT(B4,"dddd")




3 Ways to Get the Day Name for a Date
Method #1: The Number Format Drop-down Menu
Method #2: The Format Cells Dialog Window
Method #3: Use the TEXT Function


Use the Weekday Name in the Source Data of a Pivot Table





https://exceljet.net/formula/conditional-formatting-gantt-chart-weekends














8. února 2017

Google spreadsheet data visualisation

Google spreadsheet data visualisation



Power Tools for Google Sheets - ablebits.com

Power Tools - Google Sheets add on

How to Visualize Data | Sheets

Data Visualization | Fusion Tables | The Apps Show - New 2017



Blockspring for Google Sheets





https://www.youtube.com/results?search_query=google+spreadsheet+data+visualization



Power Tools

One-click solutions for daily tasks: split cells, remove duplicates, change case, find and clean up data, work with formulas & more.





Source of information


Jak mohu změnit dnech ve všech Tabulky za rok?
http://www.myartve.net/jak-mohu-zmenit-dnech-ve-vsech-tabulky-za-rok/


 5 aplikací, které vymáčknou z PrintScreenu maximum





Forex - O co se můžeme v tradingu opřít?
Statistická aplikace se blíží.
https://ziskejucet.cz/blog/se-muzeme-tradingu-oprit-statisticka-sekce-se-blizi/


Programujeme v MQL XVIII. – Tester strategií
https://ziskejucet.cz/mt4/programujeme-v-mql-xviii-tester-strategii/




Dovolená? Vezměte si 14 dní a vypněte mobil

Jídlo ze supermarketů způsobuje demenci, vydělávají na vašem přejídání, varuje odbornice










24. ledna 2017

Google Sheets - Table Styles

Google Sheets - Table Styles






Add-ons for Google Sheets

Table Styles

Add-ons for Google Docs

Add-ons for Google Sheets

Word Add-ons


Advanced Find and Replace for Google Sheets


Advanced Find and Replace for Google Sheets

Advanced search in Google spreadsheet



AbleBits.com freeware add-ins download

Add-ins for Microsoft Excel 2016, 2013, 2010-2003


The Best Chrome Extensions for Google Drive





The Best Chrome Extensions for Google Drive





Google drive database app
Google spreadsheet database
Google Analytics Reports Made Easy
How to use a Google Spreadsheet as a database



Creating an app (Database) that works with Google Sheets!





Database To Google Sheets - Database Connector


Our database connector supports 
MySQL, 
PostgresSQL, 
SqlServer, 
Oracle, 
Access, 
and more. 
Your database can be installed on a local computer or a Cloud server...







The Best Chrome Extensions for Gmail


20 Professional Tools to Automate Common Tasks in Microsoft Excel




Categories
Excel Add-ins New
Outlook plug-ins New
Excel Mac apps
Excel online add-ins
Outlook online add-ins New
Google Sheets add-ons
Google Docs add-ons
Word Add-ons
Development Tool






1. října 2016

Freezing Rows and Columns in a Google Spreadsheet

Freezing Rows and Columns in a Google Spreadsheet




How to freeze multiple rows and / or columns

How to freeze multiple rows and / or columns (Excel tips #6)



excel university





Google Sheets Make Headers in Rows or Freeze Rows and Columns




Google Sheets: Modifying Columns, Rows, and Cells





Creating an app (Database) that works with Google Sheets!




How to use Data Validation to create a drop down list in a Google spreadsheet





DYNAMIC DEPENDENT DROP DOWN LISTS IN GOOGLE SPREADSHEETS + Tools - Script Editor



Creating an app (Database) that works with Google Sheets!



F&Q AND ADVANCED OPTIONS FOR DYNAMIC DROP DOWN LISTS IN GOOGLE SPREADSHEETS



HOW TO CREATE HORIZONTAL OR "ROW" DEPENDENT DROP DOWN LISTS IN GOOGLE SPREADSHEETS

Google Sheets: Creating Simple Formulas




Google Sheets: Creating Complex Formulas





How to Extract Data from a Spreadsheet using VLOOKUP, MATCH and INDEX



How to extract data from website to excel


Automated data scraping from websites into Excel



How to extract data from multiple tables in a web page



How to Scrape Google Search Results Quickly, Easily and for Free





The Ultimate Introduction to Web Scraping and Browser Automation


Whenever you need to import data from an external website, hopefully they provide an API and make your life easy. But in the real world, that's not always the case. There are numerous reasons why you might want to get data from a web page or multiple web pages, and there's no API in sight, and in that case you're going to need to fall back onto Web Scraping and Browser Automation.

In this screencast I'm going to give a high level overview of how to scrape websites, then cover five different scenarios, in increasing difficulty, for practical web scraping. There is a massive amount of information in this screencast and I'm going to straight up bombard you with it, but if you can make it until the end I guarantee you will come out knowing how to scrape websites with the best of them.

As always, you can hit me up on twitter @AlwaysBCoding with questions, comments, to argue about programming, or to drop a suggestion for which topics I should cover next.

Jordan Leigh





Automatically Download Stock Price data from Yahoo Finance


Published on 30 Oct 2014
A walkthrough on how to write a VBA Macro in Excel to automatically download historical prices for any stock in any date range.

**UPDATE** 9/10/16 it seems that Yahoo has reversed their URL for getting the data. The End Date and the Beginning Date have reversed. So if you just swap the locations on the Excel sheet for the dates then it should work fine.
TimeValue Videos
https://sites.google.com/site/timevaluevideos/






























Zamknutí řádků a sloupců ukotvením příček







5. ledna 2015

Formulář Faktura

Formulář Faktura




Faktura - vzor ke stažení


Vystavování a uchovávání faktur v PDF


Faktura pro plátce i neplátce DPH (Excel)





Účetní doklady: Vzor faktury ke stažení


Excel návod › Formulář faktura


Formulář faktura - fakturujte v Excelu!


Excel šablony › Formulář Faktura III





Evidence docházky II

Pracovní kalendář




Děláte daňové přiznání? Zde je konkrétní příklad, co můžete uplatnit jako náklad



Víme, s jakými novinkami mají počítat OSVČ s výdajovými paušály v přiznání 2014

Přechod z OSVČ na s.r.o. Jak a kdy je to nejvhodnější?

V něčem jsou mírnější, jinde přitvrdily. Jaké jsou nově daňové sankce?



Jaké výdaje si může uplatnit OSVČ

Daňově uznatelné náklady: Co se změní v roce 2015  -  SwissLife


Výdaje a daňová (ne)uznatelnost - Pohoda

Uplatňování PHM do daňově uznatelných nákladů a povinnost k silniční dani

Učebnice - 67 3.3 Ú č etní náklady, které nejsou da ň ov ě uznatelnými



Daňový tip: 48.000 Kč do nákladů 12ti krátkými cestami


Dárky, šampaňské a pomoc nejen lidem z hlediska daní


Chcete si snížit daňovou zátěž? Přinášíme legální triky, jak na to.


Opravy a technické zhodnocení z daňového hlediska – 1. část




jak pronajimat byty.cz


Pronajímáte byt? Poradíme vám, jak s daněmi



VŠEM - Daňová uznatelnost



Chcete bezúročnou půjčku na bydlení? Přestěhujte se do socialistické Francie





30. prosince 2013

Excel Calendar Templates

Excel Calendar Templates



Excel Calendars Templates

Calendar in Excel xls format



Excel Calendar Template



CalendarPedia

Calendar - Excel Templates




UK Edition
US Edition


Word Excel PDF


School year calendars

Monthly calendars

Timetables



Goog  Calendar in Excel xls format






7. prosince 2008

unlock workbook password and sheet passwords

Unlock a workbook password and sheet passwords

Odemknutí tabulky v Excelu xls

OS:
Windows
Product:
MS Excel (2002, ..)
Description:
Kód dokáže najít hrubou silou heslo sešitu i listu. Pro použití nakopírovat kód do modulu. Pro odemčení sešitu spustit makro
UnlockWorkbookPro odemčení listu pak makro



UnlockSheet
' modUnlockRoutines
'
' Module provides Excel workbook and sheet unlock routines. The algorithm
' relies on a backdoor password that can be 1 to 9 characters long where each
' character is either an "A" or "B" except the last which can be any character
' from ASCII code 32 to 255.
'
' Implemented as a regular module for use with any Excel VBA project.
'
' Dependencies:
'
' None
'
' © 2007 Kevin M. Jones

Option Explicit

Private Sub DisplayStatus( _
ByVal PasswordsTried As Long _
)

' Display the status in the Excel status bar.
'
' Syntax
'
' DisplayStatus(PasswordsTried)
'
' PasswordsTried - The number of passwords tried thus far.

Static LastStatus As String

LastStatus = Format(PasswordsTried / 57120, "0%") & " of possible passwords tried."
If Application.StatusBar <> LastStatus Then
Application.StatusBar = LastStatus
DoEvents
End If

End Sub

Private Function TrySheetPasswordSize( _
ByVal Size As Long, _
ByRef PasswordsTried As Long, _
ByRef Password As String, _
Optional ByVal Base As String _
) As Boolean

' Try unlocking the sheet with all passwords of the specified size.
'
' TrySheetPasswordSize(Size, PasswordsTried, Password, [Base])
'
' Size - The size of the password to try.
'
' PasswordsTried - The cummulative number of passwords tried thus far.
'
' Password - The current password.
'
' Base - The base password from the calling routine.

Dim Index As Long

On Error Resume Next
If IsMissing(Base) Then Base = vbNullString
If Len(Base) < Size - 1 Then
For Index = 65 To 66
If TrySheetPasswordSize(Size, PasswordsTried, Password, Base & Chr(Index)) Then
TrySheetPasswordSize = True
Exit Function
End If
Next Index
ElseIf Len(Base) < Size Then
For Index = 32 To 255
ActiveSheet.Unprotect Base & Chr(Index)
If Not ActiveSheet.ProtectContents Then
TrySheetPasswordSize = True
Password = Base & Chr(Index)
Exit Function
End If
PasswordsTried = PasswordsTried + 1
Next Index
End If
On Error GoTo 0

DisplayStatus PasswordsTried

End Function

Private Function TryWorkbookPasswordSize( _
ByVal Size As Long, _
ByRef PasswordsTried As Long, _
ByRef Password As String, _
Optional ByVal Base As String _
) As Boolean

' Try unlocking the workbook with all passwords of the specified size.
'
' TryWorkbookPasswordSize(Size, PasswordsTried, Password, [Base])
'
' Size - The size of the password to try.
'
' PasswordsTried - The cummulative number of passwords tried thus far.
'
' Password - The current password.
'
' Base - The base password from the calling routine.

Dim Index As Long

On Error Resume Next
If IsMissing(Base) Then Base = vbNullString
If Len(Base) < Size - 1 Then
For Index = 65 To 66
If TryWorkbookPasswordSize(Size, PasswordsTried, Password, Base & Chr(Index)) Then
TryWorkbookPasswordSize = True
Exit Function
End If
Next Index
ElseIf Len(Base) < Size Then
For Index = 32 To 255
ActiveWorkbook.Unprotect Base & Chr(Index)
If Not ActiveWorkbook.ProtectStructure And Not ActiveWorkbook.ProtectWindows Then
TryWorkbookPasswordSize = True
Password = Base & Chr(Index)
Exit Function
End If
PasswordsTried = PasswordsTried + 1
Next Index
End If
On Error GoTo 0

DisplayStatus PasswordsTried

End Function

Public Sub UnlockSheet()

' Unlock the active sheet using a backdoor Excel provides where an alternate
' password is created that is more limited.

Dim PasswordSize As Variant
Dim PasswordsTried As Long
Dim Password As String

PasswordsTried = 0
If Not ActiveSheet.ProtectContents Then
MsgBox "The sheet is already unprotected."
Exit Sub
End If
On Error Resume Next
ActiveSheet.Protect ""
ActiveSheet.Unprotect ""
On Error GoTo 0
If ActiveSheet.ProtectContents Then
For Each PasswordSize In Array(5, 4, 6, 7, 8, 3, 2, 1)
If TrySheetPasswordSize(PasswordSize, PasswordsTried, Password) Then Exit For
Next PasswordSize
End If
If Not ActiveSheet.ProtectContents Then
MsgBox "The sheet " & ActiveSheet.Name & " has been unprotected with password '" & Password & "'."
End If
Application.StatusBar = False

End Sub

Public Sub UnlockWorkbook()

' Unlock the active workbook using a backdoor Excel provides where an alternate
' password is created that is more limited.

Dim PasswordSize As Variant
Dim PasswordsTried As Long
Dim Password As String

PasswordsTried = 0
If Not ActiveWorkbook.ProtectStructure And Not ActiveWorkbook.ProtectWindows Then
MsgBox "The workbook is already unprotected."
Exit Sub
End If
On Error Resume Next
ActiveWorkbook.Unprotect vbNullString
On Error GoTo 0
If ActiveWorkbook.ProtectStructure Or ActiveWorkbook.ProtectWindows Then
For Each PasswordSize In Array(5, 4, 6, 7, 8, 3, 2, 1)
If TryWorkbookPasswordSize(PasswordSize, PasswordsTried, Password) Then Exit For
Next PasswordSize
End If
If Not ActiveWorkbook.ProtectStructure And Not ActiveWorkbook.ProtectWindows Then
MsgBox "The workbook " & ActiveWorkbook.Name & " has been unprotected with password '" & Password & "'."
End If
Application.StatusBar = False

End Sub