OpenOffice Macro to fix UTF-8 and iso-8859-1 encoding issues (–, —, ”, “, Â)

I’m not exactly sure why it is happening (probably cut and paste issues), but occasionally I get some encoding errors on my blog.  Quotes and dashes end up as: –, —, ”, “. You can see an example in this photo:

2008-12-14_1741

According to this website, this is an issue of browsers not playing nice using different encoding standards: UTF-8 and iso-8859-1.  I have also run into this issue when I was downloading text from the internet and had all these characters pop up.  It’s annoying when it happens, but there is a quick fix once it has happened: a macro for OpenOffice.  I’m not an expert on this stuff by any means, but OpenOffice lets you record macros, which is what I did to create this one.  This macro converts the following:

  • – into –
  • — into –
  • ” into “
  • “ -> “
  • Â into (deletes)
  • €¦ into :
  • ï into ä
  • & into &
  • €™ into ‘
  • ’ into ‘
  • €˜ into ‘

Follow these directions to import the macro:

1) Open OpenOffice.org.  Go to: Tools -> Macros -> Organize Macros -> OpenOffice.org Basic.  This window will pop up:

2008-12-14_1743

2) Select “Organizer” and you’ll get this window:

2008-12-14_1743_2

3) Select the “libraries” tab and you’ll see this:

2008-12-14_1744

4) Create a “New” library by selecting “New”.  I called mine UTFCleanUp:

2008-12-14_1744_2

5) Hit “OK.”  Close the Organizer. Now select your new library (mine is “UTFCleanUp”).  Then select “New”:

2008-12-14_1745

6) This will pull up a new macro.  Make sure in the drop-down window it says “[My Macros & Dialogs].UTFCleanUp” (or whatever you called your library).

2008-12-14_1745_2

7) Select all (Ctrl+A).  Then paste the following:

REM ***** BASIC *****

Sub Main

End Sub

sub cleanup
rem ———————————————————————-
rem define variables
dim document as object
dim dispatcher as object
rem ———————————————————————-
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(“com.sun.star.frame.DispatchHelper”)

rem ———————————————————————-
dim args2(18) as new com.sun.star.beans.PropertyValue
args2(0).Name = “SearchItem.StyleFamily”
args2(0).Value = 2
args2(1).Name = “SearchItem.CellType”
args2(1).Value = 0
args2(2).Name = “SearchItem.RowDirection”
args2(2).Value = true
args2(3).Name = “SearchItem.AllTables”
args2(3).Value = false
args2(4).Name = “SearchItem.Backward”
args2(4).Value = false
args2(5).Name = “SearchItem.Pattern”
args2(5).Value = false
args2(6).Name = “SearchItem.Content”
args2(6).Value = false
args2(7).Name = “SearchItem.AsianOptions”
args2(7).Value = false
args2(8).Name = “SearchItem.AlgorithmType”
args2(8).Value = 0
args2(9).Name = “SearchItem.SearchFlags”
args2(9).Value = 65536
args2(10).Name = “SearchItem.SearchString”
args2(10).Value = ““”
args2(11).Name = “SearchItem.ReplaceString”
args2(11).Value = CHR$(34)
args2(12).Name = “SearchItem.Locale”
args2(12).Value = 255
args2(13).Name = “SearchItem.ChangedChars”
args2(13).Value = 2
args2(14).Name = “SearchItem.DeletedChars”
args2(14).Value = 2
args2(15).Name = “SearchItem.InsertedChars”
args2(15).Value = 2
args2(16).Name = “SearchItem.TransliterateFlags”
args2(16).Value = 1280
args2(17).Name = “SearchItem.Command”
args2(17).Value = 3
args2(18).Name = “Quiet”
args2(18).Value = true

dispatcher.executeDispatch(document, “.uno:ExecuteSearch”, “”, 0, args2())

rem ———————————————————————-
dim args4(18) as new com.sun.star.beans.PropertyValue
args4(0).Name = “SearchItem.StyleFamily”
args4(0).Value = 2
args4(1).Name = “SearchItem.CellType”
args4(1).Value = 0
args4(2).Name = “SearchItem.RowDirection”
args4(2).Value = true
args4(3).Name = “SearchItem.AllTables”
args4(3).Value = false
args4(4).Name = “SearchItem.Backward”
args4(4).Value = false
args4(5).Name = “SearchItem.Pattern”
args4(5).Value = false
args4(6).Name = “SearchItem.Content”
args4(6).Value = false
args4(7).Name = “SearchItem.AsianOptions”
args4(7).Value = false
args4(8).Name = “SearchItem.AlgorithmType”
args4(8).Value = 0
args4(9).Name = “SearchItem.SearchFlags”
args4(9).Value = 65536
args4(10).Name = “SearchItem.SearchString”
args4(10).Value = “””
args4(11).Name = “SearchItem.ReplaceString”
args4(11).Value = CHR$(34)
args4(12).Name = “SearchItem.Locale”
args4(12).Value = 255
args4(13).Name = “SearchItem.ChangedChars”
args4(13).Value = 2
args4(14).Name = “SearchItem.DeletedChars”
args4(14).Value = 2
args4(15).Name = “SearchItem.InsertedChars”
args4(15).Value = 2
args4(16).Name = “SearchItem.TransliterateFlags”
args4(16).Value = 1280
args4(17).Name = “SearchItem.Command”
args4(17).Value = 3
args4(18).Name = “Quiet”
args4(18).Value = true

dispatcher.executeDispatch(document, “.uno:ExecuteSearch”, “”, 0, args4())

rem ———————————————————————-
dim args6(18) as new com.sun.star.beans.PropertyValue
args6(0).Name = “SearchItem.StyleFamily”
args6(0).Value = 2
args6(1).Name = “SearchItem.CellType”
args6(1).Value = 0
args6(2).Name = “SearchItem.RowDirection”
args6(2).Value = true
args6(3).Name = “SearchItem.AllTables”
args6(3).Value = false
args6(4).Name = “SearchItem.Backward”
args6(4).Value = false
args6(5).Name = “SearchItem.Pattern”
args6(5).Value = false
args6(6).Name = “SearchItem.Content”
args6(6).Value = false
args6(7).Name = “SearchItem.AsianOptions”
args6(7).Value = false
args6(8).Name = “SearchItem.AlgorithmType”
args6(8).Value = 0
args6(9).Name = “SearchItem.SearchFlags”
args6(9).Value = 65536
args6(10).Name = “SearchItem.SearchString”
args6(10).Value = “–”
args6(11).Name = “SearchItem.ReplaceString”
args6(11).Value = “-”
args6(12).Name = “SearchItem.Locale”
args6(12).Value = 255
args6(13).Name = “SearchItem.ChangedChars”
args6(13).Value = 2
args6(14).Name = “SearchItem.DeletedChars”
args6(14).Value = 2
args6(15).Name = “SearchItem.InsertedChars”
args6(15).Value = 2
args6(16).Name = “SearchItem.TransliterateFlags”
args6(16).Value = 1280
args6(17).Name = “SearchItem.Command”
args6(17).Value = 3
args6(18).Name = “Quiet”
args6(18).Value = true

dispatcher.executeDispatch(document, “.uno:ExecuteSearch”, “”, 0, args6())

rem ———————————————————————-
dim args8(18) as new com.sun.star.beans.PropertyValue
args8(0).Name = “SearchItem.StyleFamily”
args8(0).Value = 2
args8(1).Name = “SearchItem.CellType”
args8(1).Value = 0
args8(2).Name = “SearchItem.RowDirection”
args8(2).Value = true
args8(3).Name = “SearchItem.AllTables”
args8(3).Value = false
args8(4).Name = “SearchItem.Backward”
args8(4).Value = false
args8(5).Name = “SearchItem.Pattern”
args8(5).Value = false
args8(6).Name = “SearchItem.Content”
args8(6).Value = false
args8(7).Name = “SearchItem.AsianOptions”
args8(7).Value = false
args8(8).Name = “SearchItem.AlgorithmType”
args8(8).Value = 0
args8(9).Name = “SearchItem.SearchFlags”
args8(9).Value = 65536
args8(10).Name = “SearchItem.SearchString”
args8(10).Value = “—”
args8(11).Name = “SearchItem.ReplaceString”
args8(11).Value = “-”
args8(12).Name = “SearchItem.Locale”
args8(12).Value = 255
args8(13).Name = “SearchItem.ChangedChars”
args8(13).Value = 2
args8(14).Name = “SearchItem.DeletedChars”
args8(14).Value = 2
args8(15).Name = “SearchItem.InsertedChars”
args8(15).Value = 2
args8(16).Name = “SearchItem.TransliterateFlags”
args8(16).Value = 1280
args8(17).Name = “SearchItem.Command”
args8(17).Value = 3
args8(18).Name = “Quiet”
args8(18).Value = true

dispatcher.executeDispatch(document, “.uno:ExecuteSearch”, “”, 0, args8())

rem ———————————————————————-
dim args10(18) as new com.sun.star.beans.PropertyValue
args10(0).Name = “SearchItem.StyleFamily”
args10(0).Value = 2
args10(1).Name = “SearchItem.CellType”
args10(1).Value = 0
args10(2).Name = “SearchItem.RowDirection”
args10(2).Value = true
args10(3).Name = “SearchItem.AllTables”
args10(3).Value = false
args10(4).Name = “SearchItem.Backward”
args10(4).Value = false
args10(5).Name = “SearchItem.Pattern”
args10(5).Value = false
args10(6).Name = “SearchItem.Content”
args10(6).Value = false
args10(7).Name = “SearchItem.AsianOptions”
args10(7).Value = false
args10(8).Name = “SearchItem.AlgorithmType”
args10(8).Value = 0
args10(9).Name = “SearchItem.SearchFlags”
args10(9).Value = 65536
args10(10).Name = “SearchItem.SearchString”
args10(10).Value = “”
args10(11).Name = “SearchItem.ReplaceString”
args10(11).Value = “”
args10(12).Name = “SearchItem.Locale”
args10(12).Value = 255
args10(13).Name = “SearchItem.ChangedChars”
args10(13).Value = 2
args10(14).Name = “SearchItem.DeletedChars”
args10(14).Value = 2
args10(15).Name = “SearchItem.InsertedChars”
args10(15).Value = 2
args10(16).Name = “SearchItem.TransliterateFlags”
args10(16).Value = 1280
args10(17).Name = “SearchItem.Command”
args10(17).Value = 3
args10(18).Name = “Quiet”
args10(18).Value = true

dispatcher.executeDispatch(document, “.uno:ExecuteSearch”, “”, 0, args10())

rem ———————————————————————-
dim args13(18) as new com.sun.star.beans.PropertyValue
args13(0).Name = “SearchItem.StyleFamily”
args13(0).Value = 2
args13(1).Name = “SearchItem.CellType”
args13(1).Value = 0
args13(2).Name = “SearchItem.RowDirection”
args13(2).Value = true
args13(3).Name = “SearchItem.AllTables”
args13(3).Value = false
args13(4).Name = “SearchItem.Backward”
args13(4).Value = false
args13(5).Name = “SearchItem.Pattern”
args13(5).Value = false
args13(6).Name = “SearchItem.Content”
args13(6).Value = false
args13(7).Name = “SearchItem.AsianOptions”
args13(7).Value = false
args13(8).Name = “SearchItem.AlgorithmType”
args13(8).Value = 0
args13(9).Name = “SearchItem.SearchFlags”
args13(9).Value = 65536
args13(10).Name = “SearchItem.SearchString”
args13(10).Value = “ï”
args13(11).Name = “SearchItem.ReplaceString”
args13(11).Value = “ä”
args13(12).Name = “SearchItem.Locale”
args13(12).Value = 255
args13(13).Name = “SearchItem.ChangedChars”
args13(13).Value = 2
args13(14).Name = “SearchItem.DeletedChars”
args13(14).Value = 2
args13(15).Name = “SearchItem.InsertedChars”
args13(15).Value = 2
args13(16).Name = “SearchItem.TransliterateFlags”
args13(16).Value = 1280
args13(17).Name = “SearchItem.Command”
args13(17).Value = 3
args13(18).Name = “Quiet”
args13(18).Value = true

dispatcher.executeDispatch(document, “.uno:ExecuteSearch”, “”, 0, args13())

rem ———————————————————————-
dim args19(18) as new com.sun.star.beans.PropertyValue
args19(0).Name = “SearchItem.StyleFamily”
args19(0).Value = 2
args19(1).Name = “SearchItem.CellType”
args19(1).Value = 0
args19(2).Name = “SearchItem.RowDirection”
args19(2).Value = true
args19(3).Name = “SearchItem.AllTables”
args19(3).Value = false
args19(4).Name = “SearchItem.Backward”
args19(4).Value = false
args19(5).Name = “SearchItem.Pattern”
args19(5).Value = false
args19(6).Name = “SearchItem.Content”
args19(6).Value = false
args19(7).Name = “SearchItem.AsianOptions”
args19(7).Value = false
args19(8).Name = “SearchItem.AlgorithmType”
args19(8).Value = 0
args19(9).Name = “SearchItem.SearchFlags”
args19(9).Value = 65536
args19(10).Name = “SearchItem.SearchString”
args19(10).Value = “’”
args19(11).Name = “SearchItem.ReplaceString”
args19(11).Value = “‘”
args19(12).Name = “SearchItem.Locale”
args19(12).Value = 255
args19(13).Name = “SearchItem.ChangedChars”
args19(13).Value = 2
args19(14).Name = “SearchItem.DeletedChars”
args19(14).Value = 2
args19(15).Name = “SearchItem.InsertedChars”
args19(15).Value = 2
args19(16).Name = “SearchItem.TransliterateFlags”
args19(16).Value = 1280
args19(17).Name = “SearchItem.Command”
args19(17).Value = 3
args19(18).Name = “Quiet”
args19(18).Value = true

dispatcher.executeDispatch(document, “.uno:ExecuteSearch”, “”, 0, args19())

rem ———————————————————————-
dim args20(18) as new com.sun.star.beans.PropertyValue
args20(0).Name = “SearchItem.StyleFamily”
args20(0).Value = 2
args20(1).Name = “SearchItem.CellType”
args20(1).Value = 0
args20(2).Name = “SearchItem.RowDirection”
args20(2).Value = true
args20(3).Name = “SearchItem.AllTables”
args20(3).Value = false
args20(4).Name = “SearchItem.Backward”
args20(4).Value = false
args20(5).Name = “SearchItem.Pattern”
args20(5).Value = false
args20(6).Name = “SearchItem.Content”
args20(6).Value = false
args20(7).Name = “SearchItem.AsianOptions”
args20(7).Value = false
args20(8).Name = “SearchItem.AlgorithmType”
args20(8).Value = 0
args20(9).Name = “SearchItem.SearchFlags”
args20(9).Value = 65536
args20(10).Name = “SearchItem.SearchString”
args20(10).Value = “€™”
args20(11).Name = “SearchItem.ReplaceString”
args20(11).Value = “‘”
args20(12).Name = “SearchItem.Locale”
args20(12).Value = 255
args20(13).Name = “SearchItem.ChangedChars”
args20(13).Value = 2
args20(14).Name = “SearchItem.DeletedChars”
args20(14).Value = 2
args20(15).Name = “SearchItem.InsertedChars”
args20(15).Value = 2
args20(16).Name = “SearchItem.TransliterateFlags”
args20(16).Value = 1280
args20(17).Name = “SearchItem.Command”
args20(17).Value = 3
args20(18).Name = “Quiet”
args20(18).Value = true

dispatcher.executeDispatch(document, “.uno:ExecuteSearch”, “”, 0, args20())

rem ———————————————————————-
dim args21(18) as new com.sun.star.beans.PropertyValue
args21(0).Name = “SearchItem.StyleFamily”
args21(0).Value = 2
args21(1).Name = “SearchItem.CellType”
args21(1).Value = 0
args21(2).Name = “SearchItem.RowDirection”
args21(2).Value = true
args21(3).Name = “SearchItem.AllTables”
args21(3).Value = false
args21(4).Name = “SearchItem.Backward”
args21(4).Value = false
args21(5).Name = “SearchItem.Pattern”
args21(5).Value = false
args21(6).Name = “SearchItem.Content”
args21(6).Value = false
args21(7).Name = “SearchItem.AsianOptions”
args21(7).Value = false
args21(8).Name = “SearchItem.AlgorithmType”
args21(8).Value = 0
args21(9).Name = “SearchItem.SearchFlags”
args21(9).Value = 65536
args21(10).Name = “SearchItem.SearchString”
args21(10).Value = “€¦”
args21(11).Name = “SearchItem.ReplaceString”
args21(11).Value = “:”
args21(12).Name = “SearchItem.Locale”
args21(12).Value = 255
args21(13).Name = “SearchItem.ChangedChars”
args21(13).Value = 2
args21(14).Name = “SearchItem.DeletedChars”
args21(14).Value = 2
args21(15).Name = “SearchItem.InsertedChars”
args21(15).Value = 2
args21(16).Name = “SearchItem.TransliterateFlags”
args21(16).Value = 1280
args21(17).Name = “SearchItem.Command”
args21(17).Value = 3
args21(18).Name = “Quiet”
args21(18).Value = true

dispatcher.executeDispatch(document, “.uno:ExecuteSearch”, “”, 0, args21())

rem ———————————————————————-
dim args22(18) as new com.sun.star.beans.PropertyValue
args22(0).Name = “SearchItem.StyleFamily”
args22(0).Value = 2
args22(1).Name = “SearchItem.CellType”
args22(1).Value = 0
args22(2).Name = “SearchItem.RowDirection”
args22(2).Value = true
args22(3).Name = “SearchItem.AllTables”
args22(3).Value = false
args22(4).Name = “SearchItem.Backward”
args22(4).Value = false
args22(5).Name = “SearchItem.Pattern”
args22(5).Value = false
args22(6).Name = “SearchItem.Content”
args22(6).Value = false
args22(7).Name = “SearchItem.AsianOptions”
args22(7).Value = false
args22(8).Name = “SearchItem.AlgorithmType”
args22(8).Value = 0
args22(9).Name = “SearchItem.SearchFlags”
args22(9).Value = 65536
args22(10).Name = “SearchItem.SearchString”
args22(10).Value = “&”
args22(11).Name = “SearchItem.ReplaceString”
args22(11).Value = “&”
args22(12).Name = “SearchItem.Locale”
args22(12).Value = 255
args22(13).Name = “SearchItem.ChangedChars”
args22(13).Value = 2
args22(14).Name = “SearchItem.DeletedChars”
args22(14).Value = 2
args22(15).Name = “SearchItem.InsertedChars”
args22(15).Value = 2
args22(16).Name = “SearchItem.TransliterateFlags”
args22(16).Value = 1280
args22(17).Name = “SearchItem.Command”
args22(17).Value = 3
args22(18).Name = “Quiet”
args22(18).Value = true

dispatcher.executeDispatch(document, “.uno:ExecuteSearch”, “”, 0, args22())

rem ———————————————————————-
dim args23(18) as new com.sun.star.beans.PropertyValue
args23(0).Name = “SearchItem.StyleFamily”
args23(0).Value = 2
args23(1).Name = “SearchItem.CellType”
args23(1).Value = 0
args23(2).Name = “SearchItem.RowDirection”
args23(2).Value = true
args23(3).Name = “SearchItem.AllTables”
args23(3).Value = false
args23(4).Name = “SearchItem.Backward”
args23(4).Value = false
args23(5).Name = “SearchItem.Pattern”
args23(5).Value = false
args23(6).Name = “SearchItem.Content”
args23(6).Value = false
args23(7).Name = “SearchItem.AsianOptions”
args23(7).Value = false
args23(8).Name = “SearchItem.AlgorithmType”
args23(8).Value = 0
args23(9).Name = “SearchItem.SearchFlags”
args23(9).Value = 65536
args23(10).Name = “SearchItem.SearchString”
args23(10).Value = “€˜”
args23(11).Name = “SearchItem.ReplaceString”
args23(11).Value = “‘”
args23(12).Name = “SearchItem.Locale”
args23(12).Value = 255
args23(13).Name = “SearchItem.ChangedChars”
args23(13).Value = 2
args23(14).Name = “SearchItem.DeletedChars”
args23(14).Value = 2
args23(15).Name = “SearchItem.InsertedChars”
args23(15).Value = 2
args23(16).Name = “SearchItem.TransliterateFlags”
args23(16).Value = 1280
args23(17).Name = “SearchItem.Command”
args23(17).Value = 3
args23(18).Name = “Quiet”
args23(18).Value = true

dispatcher.executeDispatch(document, “.uno:ExecuteSearch”, “”, 0, args23())

end sub

(In case you have a problem copying and pasting the code for the macro, here it is a text file.)

8) You’ll end up with this:

2008-12-14_1746

9) Save your macro (click on the blue disk).

10) You can access your macro by going to: Tools -> Macros -> Run Macros

11) Select: My Macros -> UTFCleanUp -> Module1 -> cleanup

12) Hit “Run”.