With a macro | Nov 23, 2011 |
István Hirsch wrote: you do not have to perform Find/Replace 32 times. Just download a software capable of performing batch replace (for example Advanced Find and Replace /free download/) and replace everything in a single step. There’s no need in any third-party software, as you can do it within a word processor. Here’s a macro for OpenOffice.org/LibreOffice: Code:
| REM ***** Recode from cp1252 to cp1251 for Word and Excel files without language set.
REM ***** Authors Dmitry G. Mastrukov and A. Novodroskii 2002
REM ***** GPL license
Dim mCP1252(123) As String
Dim mCP1251(123) As String
Sub Init
mCP1252() = Array("€","‚","¸","„","…","†","‡","ˆ","‰","Š","‹","Œ","Ž", _
"‘","’","“","”","•","–","—","™","š","›","œ","¡","ž", _
"Ÿ"," ","¡","¢","£","¤","¥","¦","§","¨","©","ª","«", _
"¬","","®","¯","°","±","²","³","´","µ","¶","·","¸", _
"¹","º","»","¼","½","¾","¿","À","Á","Â","Ã","Ä","Å", _
"Æ","Ç","È","É","Ê","Ë","Ì","Í","Î","Ï","Ð","Ñ","Ò", _
"Ó","Ô","Õ","Ö","×","Ø","Ù","Ú","Û","Ü","Ý","Þ","ß", _
"à","á","â","ã","ä","å","æ","ç","è","é","ê","ë","ì", _
"í","î","ï","ð","ñ","ò","ó","ô","õ","ö","÷","ø","ù", _
"ú","û","ü","ý","þ","ÿ")
mCP1251() = Array("Ђ","‚","ё","„","…","†","‡","€","‰","Љ","‹","Њ","Ћ", _
"‘","’","“","”","•","–","—","™","љ","›","њ","ќ","ћ", _
"џ"," ","Ў","ў","Ј","¤","Ґ","¦","§","Ё","©","Є","«", _
"¬","","®","Ї","°","±","І","і","ґ","µ","¶","·","ё", _
"№","є","»","ј","Ѕ","ѕ","ї","А","Б","В","Г","Д","Е", _
"Ж","З","И","Й","К","Л","М","Н","О","П","Р","С","Т", _
"У","Ф","Х","Ц","Ч","Ш","Щ","Ъ","Ы","Ь","Э","Ю","Я", _
"а","б","в","г","д","е","ж","з","и","й","к","л","м", _
"н","о","п","р","с","т","у","ф","х","ц","ч","ш","щ", _
"ъ","ы","ь","э","ю","я")
End Sub
Sub RecodeAllWriter
Dim n As Long
Dim oDocument As Object
Dim oReplace As Object
Init()
oDocument = ThisComponent
oReplace = oDocument.createReplaceDescriptor
For n = lbound(mCP1252()) To ubound(mCP1252())
oReplace.SearchString = mCP1252(n)
oReplace.ReplaceString = mCP1251(n)
oReplace.SearchCaseSensitive = TRUE
oDocument.replaceAll(oReplace)
Next n
MsgBox "Преобразовано"
End Sub
Sub RecodeAllCalc
Dim n As Long
Dim m As Long
Dim oDocument As Object
Dim oReplace As Object
Init()
On error goto ex
oDocument = ThisComponent
m = 0
While 1 = 1
oReplace = oDocument.Sheets(m).createReplaceDescriptor
For n = lbound(mCP1252()) To ubound(mCP1252())
oReplace.SearchString = mCP1252(n)
oReplace.ReplaceString = mCP1251(n)
oReplace.SearchCaseSensitive = TRUE
oDocument.Sheets(m).replaceAll(oReplace)
Next n
m = m + 1
Wend
ex:
MsgBox "Преобразовано"
End Sub |
|
The macro cures the situation as described in the initial posting (i. e., a document created in a pre-Unicode version of MS Word or Excel with a non-Unicode font with the language incorrectly specified). Obviously, a similar code can be written for MS Word, but I’m not proficient in VBA. However, for Uzbek another solution is (very likely) needed.
[Edited at 2011-11-23 08:27 GMT] | |