Gebruiker:Pommée/ReplaceFlagicon
Uiterlijk
Sub ReplaceFlagicon()
'
' ReplaceFlagicon Macro
' Macro initially recorded woensdag 5 december 2012 by Pommée
' Version: 2020-05-17 23:35
'
Dim saveAF As Boolean
Dim countryNameOrCode As String
Dim yearNumber As String
saveAF = Options.AutoFormatAsYouTypeReplaceQuotes
Options.AutoFormatAsYouTypeReplaceQuotes = False
ActiveDocument.Bookmarks.Add Name:="Origin"
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection.Find
.Text = "{{bandiera|"
.Replacement.Text = "{{flagicon|"
.Execute Replace:=wdReplaceAll
.Text = "|size=22px}}"
.Replacement.Text = "}}"
.Execute Replace:=wdReplaceAll
.Text = "}}''' [["
.Replacement.Text = "}} '''[["
.Execute Replace:=wdReplaceAll
.Text = "{{flagicon|}}"
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
End With
NextFlag:
Selection.Find.Text = "{{flagicon|"
If not Selection.Find.Execute Then GoTo EndFlags:
MarkingStart = Selection.Range.Start
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Do While Selection.Characters.Item(Selection.Characters.Count) <> "|" And _
Selection.Characters.Item(Selection.Characters.Count) <> "}"
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Loop
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend ' | cq } weer eraf
countryNameOrCode = Selection.Text
Selection.MoveRight Unit:=wdCharacter, Count:=1
If Selection.Characters.Item(1) = "}" Then
yearNumber = " "
ElseIf Selection.Characters.Item(1) = "|" Then
Selection.MoveRight Unit:=wdCharacter, Count:=1
If Selection.Characters.Item(1) = "|" Or Selection.Characters.Item(1) = "}" Then
yearNumber = " "
Else
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Do While Selection.Characters.Item(Selection.Characters.Count) <> "|" And _
Selection.Characters.Item(Selection.Characters.Count) <> "}"
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Loop
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend ' | cq } weer eraf
yearNumber = Selection.Text
Selection.MoveRight Unit:=wdCharacter, Count:=1
End If
Do While Selection.Characters.Item(1) <> "}"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Loop
Else
GoTo FailExit:
End If
' Get rid of exceptions:
If countryNameOrCode = "BLR" And yearNumber = "1995" Then yearNumber = " "
If countryNameOrCode = "ESP" And yearNumber = "1945" Then yearNumber = "1939"
If countryNameOrCode = "FRG" And yearNumber = " " Then yearNumber = "1949"
If countryNameOrCode = "GER" And yearNumber = "Weimar" Then yearNumber = "1919"
If countryNameOrCode = "JPN" And yearNumber = "1870" Then yearNumber = " "
If countryNameOrCode = "JPN" And yearNumber = "1947" Then yearNumber = " "
If countryNameOrCode = "Kingdom of Yugoslavia" And yearNumber = " " Then yearNumber = "1918"
If countryNameOrCode = "RHO" And yearNumber = " " Then yearNumber = "1968"
If countryNameOrCode = "Union of South Africa" And yearNumber = " " Then yearNumber = "1928"
If countryNameOrCode = "RSA" And yearNumber = "1912" Then yearNumber = "1910"
If countryNameOrCode = "SFR Yugoslavia" And yearNumber = " " Then yearNumber = "1943"
If countryNameOrCode = "VEN 1930-2006" And yearNumber = " " Then yearNumber = "1930"
If countryNameOrCode = "West Germany" And yearNumber = " " Then yearNumber = "1949"
If countryNameOrCode = "ZAF 1928-1994" And yearNumber = " " Then yearNumber = "1928"
Select Case countryNameOrCode
Case "ALG"
countryNameOrCode = "DZ"
Case "AND"
countryNameOrCode = "AD"
Case "Argentina"
countryNameOrCode = "AR"
Case "ARG"
countryNameOrCode = "AR"
Case "ARM"
countryNameOrCode = "AM"
Case "Australia"
countryNameOrCode = "AU"
Case "AUS"
countryNameOrCode = "AU"
Case "Austria"
countryNameOrCode = "AT"
Case "AUT"
countryNameOrCode = "AT"
Case "AZE"
countryNameOrCode = "AZ"
Case "Bahamas"
countryNameOrCode = "BS"
Case "BAH"
countryNameOrCode = "BS"
Case "BDI"
countryNameOrCode = "BI"
Case "Belgium"
countryNameOrCode = "BE"
Case "BEL"
countryNameOrCode = "BE"
Case "BEN"
countryNameOrCode = "BJ"
Case "BGR"
countryNameOrCode = "BG"
Case "BIH"
countryNameOrCode = "BA"
Case "BHS"
countryNameOrCode = "BS"
Case "BLR"
countryNameOrCode = "BY"
Case "Belarus"
countryNameOrCode = "BY"
Case "BOL"
countryNameOrCode = "BO"
Case "Brazil"
countryNameOrCode = "BR"
Case "BRA"
countryNameOrCode = "BR"
Case "Bulgaria"
countryNameOrCode = "BG"
Case "BUL"
countryNameOrCode = "BG"
Case "CAM"
countryNameOrCode = "KH"
Case "Canada"
countryNameOrCode = "CA"
Case "CAN"
countryNameOrCode = "CA"
Case "CHE"
countryNameOrCode = "CH"
Case "Chile"
countryNameOrCode = "CL"
Case "CHI"
countryNameOrCode = "CL"
Case "CHL"
countryNameOrCode = "CL"
Case "China"
countryNameOrCode = "CN"
Case "CHN"
countryNameOrCode = "CN"
Case "CIS"
countryNameOrCode = "GOS"
Case "CIV"
countryNameOrCode = "CI"
Case "Colombia"
countryNameOrCode = "CO"
Case "COL"
countryNameOrCode = "CO"
Case "CRC"
countryNameOrCode = "CR"
Case "Czechoslovakia"
countryNameOrCode = "CSHH"
Case "CSK"
countryNameOrCode = "CSHH"
Case "Croatia"
countryNameOrCode = "HR"
Case "CRO"
countryNameOrCode = "HR"
Case "CYP"
countryNameOrCode = "CY"
Case "Czech Republic"
countryNameOrCode = "CZ"
Case "CZE"
countryNameOrCode = "CZ"
Case "Denmark"
countryNameOrCode = "DK"
Case "DEN"
countryNameOrCode = "DK"
Case "DNK"
countryNameOrCode = "DK"
Case "DEU"
countryNameOrCode = "DE"
Case "DOM"
countryNameOrCode = "DO"
Case "DZA"
countryNameOrCode = "DZ"
Case "ECU"
countryNameOrCode = "EC"
Case "EGY"
countryNameOrCode = "EG"
Case "ESA"
countryNameOrCode = "SV"
Case "Spain"
countryNameOrCode = "ES"
Case "ESP"
countryNameOrCode = "ES"
Case "Estonia"
countryNameOrCode = "EE"
Case "EST"
countryNameOrCode = "EE"
Case "EUN"
countryNameOrCode = "SUHH-UT"
Case "Finland"
countryNameOrCode = "FI"
Case "FIN"
countryNameOrCode = "FI"
Case "FR Yugoslavia"
countryNameOrCode = "YUCS"
Case "France"
countryNameOrCode = "FR"
Case "FRA"
countryNameOrCode = "FR"
Case "FRG"
countryNameOrCode = "DE"
Case "FRY"
countryNameOrCode = "YUCS"
Case "Great Britain"
countryNameOrCode = "UK"
Case "GBR"
countryNameOrCode = "UK"
Case "GRB"
countryNameOrCode = "UK"
Case "Georgia (country)"
countryNameOrCode = "GE"
Case "GEO"
countryNameOrCode = "GE"
Case "Germany"
countryNameOrCode = "DE"
Case "GER"
countryNameOrCode = "DE"
Case "GRC"
countryNameOrCode = "GR"
Case "GRE"
countryNameOrCode = "GR"
Case "GUA"
countryNameOrCode = "GT"
Case "HAI"
countryNameOrCode = "HT"
Case "HKG"
countryNameOrCode = "HK"
Case "HRV"
countryNameOrCode = "HR"
Case "Hungary"
countryNameOrCode = "HU"
Case "HUN"
countryNameOrCode = "HU"
Case "IDN"
countryNameOrCode = "ID"
Case "INA"
countryNameOrCode = "ID"
Case "India"
countryNameOrCode = "IN"
Case "IND"
countryNameOrCode = "IN"
Case "IOP"
countryNameOrCode = "IOP"
Case "IRE"
countryNameOrCode = "IE"
Case "IRI"
countryNameOrCode = "IR"
Case "IRL"
countryNameOrCode = "IE"
Case "IRN"
countryNameOrCode = "IR"
Case "Israel"
countryNameOrCode = "IL"
Case "ISR"
countryNameOrCode = "IL"
Case "Italy"
countryNameOrCode = "IT"
Case "ITA"
countryNameOrCode = "IT"
Case "JAM"
countryNameOrCode = "JM"
Case "Japan"
countryNameOrCode = "JP"
Case "JPN"
countryNameOrCode = "JP"
Case "KAZ"
countryNameOrCode = "KZ"
Case "KGZ"
countryNameOrCode = "KG"
Case "Kingdom of Yugoslavia"
countryNameOrCode = "YUCS"
Case "KOR"
countryNameOrCode = "KR"
Case "LAT"
countryNameOrCode = "LV"
Case "Latvia"
countryNameOrCode = "LV"
Case "LIE"
countryNameOrCode = "LI"
Case "LTU"
countryNameOrCode = "LT"
Case "LUX"
countryNameOrCode = "LU"
Case "LVA"
countryNameOrCode = "LV"
Case "MAD"
countryNameOrCode = "MG"
Case "MAR"
countryNameOrCode = "MA"
Case "MAS"
countryNameOrCode = "MY"
Case "MYS"
countryNameOrCode = "MY"
Case "MDA"
countryNameOrCode = "MD"
Case "MDG"
countryNameOrCode = "MG"
Case "MEX"
countryNameOrCode = "MX"
Case "Mexico"
countryNameOrCode = "MX"
Case "MKD"
countryNameOrCode = "MK"
Case "MNE"
countryNameOrCode = "ME"
Case "MON"
countryNameOrCode = "MC"
Case "NAM"
countryNameOrCode = "NA"
Case "Netherlands"
countryNameOrCode = "NL"
Case "NED"
countryNameOrCode = "NL"
Case "NLD"
countryNameOrCode = "NL"
Case "NGR"
countryNameOrCode = "NG"
Case "NOR"
countryNameOrCode = "NO"
Case "New Zealand"
countryNameOrCode = "NZ"
Case "NZL"
countryNameOrCode = "NZ"
Case "OMA"
countryNameOrCode = "OM"
Case "PAK"
countryNameOrCode = "PK"
Case "Paraguay"
countryNameOrCode = "PY"
Case "PAR"
countryNameOrCode = "PY"
Case "People's Republic of China"
countryNameOrCode = "CN"
Case "PRC"
countryNameOrCode = "CN"
Case "PER"
countryNameOrCode = "PE"
Case "PHI"
countryNameOrCode = "PH"
Case "PHL"
countryNameOrCode = "PH"
Case "PNG"
countryNameOrCode = "PG"
Case "Poland"
countryNameOrCode = "PL"
Case "POL"
countryNameOrCode = "PL"
Case "POR"
countryNameOrCode = "PT"
Case "PRI"
countryNameOrCode = "PR"
Case "PRT"
countryNameOrCode = "PT"
Case "PRY"
countryNameOrCode = "PY"
Case "Puerto Rico"
countryNameOrCode = "PR"
Case "PUR"
countryNameOrCode = "PR"
Case "Qatar"
countryNameOrCode = "QA"
Case "QAT"
countryNameOrCode = "QA"
Case "Rhodesia"
countryNameOrCode = "RHZW"
Case "RHO"
countryNameOrCode = "RHZW"
Case "Romania"
countryNameOrCode = "RO"
Case "ROM"
countryNameOrCode = "RO"
Case "ROU"
countryNameOrCode = "RO"
Case "South Africa"
countryNameOrCode = "ZA"
Case "Union of South Africa"
countryNameOrCode = "ZA"
Case "RSA"
countryNameOrCode = "ZA"
Case "Russian Federation"
countryNameOrCode = "RU"
Case "Russia"
countryNameOrCode = "RU"
Case "RUS"
countryNameOrCode = "RU"
Case "RUS|1991"
countryNameOrCode = "RU"
Case "SCG"
countryNameOrCode = "CSXX"
Case "Serbia"
countryNameOrCode = "RS"
Case "SER"
countryNameOrCode = "RS"
Case "SFR Yugoslavia"
countryNameOrCode = "YUCS"
Case "SGP"
countryNameOrCode = "SG"
Case "SIN"
countryNameOrCode = "SG"
Case "Slovenia"
countryNameOrCode = "SI"
Case "SLO"
countryNameOrCode = "SI"
Case "SLV"
countryNameOrCode = "SV"
Case "Soviet Union"
countryNameOrCode = "SUHH"
Case "SRB"
countryNameOrCode = "RS"
Case "SVK"
countryNameOrCode = "SK"
Case "Slovakia"
countryNameOrCode = "SK"
Case "SVN"
countryNameOrCode = "SI"
Case "SWE"
countryNameOrCode = "SE"
Case "Switzerland"
countryNameOrCode = "CH"
Case "SUI"
countryNameOrCode = "CH"
Case "SWI"
countryNameOrCode = "CH"
Case "TCH"
countryNameOrCode = "CSHH"
Case "THA"
countryNameOrCode = "TH"
Case "TPE"
countryNameOrCode = "XT"
Case "TAI"
countryNameOrCode = "XT"
Case "TUN"
countryNameOrCode = "TN"
Case "Turkey"
countryNameOrCode = "TR"
Case "TUR"
countryNameOrCode = "TR"
Case "TWN"
countryNameOrCode = "TW"
Case "UK"
countryNameOrCode = "UK"
Case "Ukraine"
countryNameOrCode = "UA"
Case "UKR"
countryNameOrCode = "UA"
Case "United Kingdom"
countryNameOrCode = "UK"
Case "URS"
countryNameOrCode = "SUHH"
Case "USSR"
countryNameOrCode = "SUHH"
Case "Uruguay"
countryNameOrCode = "UY"
Case "URU"
countryNameOrCode = "UY"
Case "URY"
countryNameOrCode = "UY"
Case "United States of America"
countryNameOrCode = "US"
Case "United States"
countryNameOrCode = "US"
Case "USA"
countryNameOrCode = "US"
Case "Uzbekistan"
countryNameOrCode = "UZ"
Case "UZB"
countryNameOrCode = "UZ"
Case "VEN"
countryNameOrCode = "VE"
Case "VEN 1930-2006"
countryNameOrCode = "VE"
Case "West Germany"
countryNameOrCode = "DE"
Case "YUG"
countryNameOrCode = "YUCS"
Case "ZAF"
countryNameOrCode = "ZA"
Case "ZAF 1928-1994"
countryNameOrCode = "ZA"
Case "ZIM"
countryNameOrCode = "ZW"
Case "Zimbabwe"
countryNameOrCode = "ZW"
Case "ZWE"
countryNameOrCode = "ZW"
Case Else
countryNameOrCode = countryNameOrCode & "??"
End Select
If countryNameOrCode = "RHZW" And yearNumber = " " Then yearNumber = "1968"
Selection.MoveStart Unit:=wdCharacter, _
Count:=MarkingStart - Selection.Range.Start
Selection.TypeText ("{{" & countryNameOrCode)
If yearNumber <> " " Then Selection.TypeText ("-" & yearNumber)
Selection.TypeText ("-VLAG")
GoTo NextFlag:
EndFlags:
ActiveDocument.Bookmarks("Origin").Select
Selection.Find.Text = "??-VLAG"
If Selection.Find.Execute Then
MsgBox ("Some flags were not translated.")
Else
ActiveDocument.Bookmarks("Origin").Delete
End If
Options.AutoFormatAsYouTypeReplaceQuotes = saveAF
FailExit:
End Sub