Code:
'======================================================================
Sub Convert_Cedila_In_Virgula()
Dim timp As Single: timp = Timer
Options.DefaultHighlightColorIndex = wdYellow 'sterge linia asta pentru a nu evidentia schimbarile
Dim perechi() As Variant
perechi = Array(ChrW(350), ChrW(536), _
ChrW(351), ChrW(537), _
ChrW(354), ChrW(538), _
ChrW(355), ChrW(539))
InlocuiriMultiple lista:=perechi, cu_meta:=False
MsgBox "Numarul total de cuvinte: " & ActiveDocument.Words.count & _
", timp de executie: " & Format(Round(Timer - timp, 3), "0.###") & " secunde", vbOKOnly, _
"Convert_Cedila_In_Virgula"
End Sub
'======================================================================
'======================================================================
Sub Convert_Virgula_In_Cedila()
Dim timp As Single: timp = Timer
Options.DefaultHighlightColorIndex = wdBrightGreen 'sterge linia asta pentru a nu evidentia schimbarile
Dim perechi() As Variant
perechi = Array(ChrW(536), ChrW(350), _
ChrW(537), ChrW(351), _
ChrW(538), ChrW(354), _
ChrW(539), ChrW(355))
InlocuiriMultiple lista:=perechi, cu_meta:=False
MsgBox "Numarul total de cuvinte: " & ActiveDocument.Words.count & _
", timp de executie: " & Format(Round(Timer - timp, 3), "0.###") & " secunde", vbOKOnly, _
"Convert_Virgula_In_Cedila"
End Sub
'======================================================================
'======================================================================
Sub Convert_In_Ortografie_Clasica()
Dim timp As Single: timp = Timer
Options.DefaultHighlightColorIndex = wdGray25 'sterge linia asta pentru a nu evidentia schimbarile
Dim perechi() As Variant
perechi = Array("<([Ss])unt", "\1înt", _
"<SUNT", "SÎNT", _
"â", "î", _
"Â", "Î", _
"<([Rr]om)î", "\1â", _
"<ROMÎ", "ROMÂ")
InlocuiriMultiple lista:=perechi, cu_meta:=True
MsgBox "Numarul total de cuvinte: " & ActiveDocument.Words.count & _
", timp de executie: " & Format(Round(Timer - timp, 3), "0.###") & " secunde", vbOKOnly, _
"Convert_In_Ortografie_Clasica"
End Sub
'======================================================================
'======================================================================
Sub Convert_In_Ortografie_Contemporana()
Dim timp As Single: timp = Timer
Options.DefaultHighlightColorIndex = wdTurquoise 'sterge linia asta pentru a nu evidentia schimbarile
Dim perechi() As Variant
' modificari generale
perechi = Array("<([Ss])înt", "\1unt", _
"<SÎNT", "SUNT", _
"î", "â", _
"Î", "Â", _
"<â", "î", _
"<Â", "Î", _
"â>", "î", _
"Â>", "Î")
InlocuiriMultiple lista:=perechi, cu_meta:=True
' refacere cuvinte compuse <prefix>î - partea 1
perechi = Array("<([aA]lt)â", "\1î", _
"<([aA]nti)â", "\1î", _
"<([aA]rhi)â", "\1î", _
"<([aA]toate)â", "\1î", _
"<([aA]tot)â", "\1î", _
"<([aA]uto)â", "\1î", _
"<([bB]ine)â", "\1î", _
"<([bB]io)â", "\1î", _
"<([bB]un)â", "\1î", _
"<([cC]ap)â", "\1î", _
"<([cC]o)â", "\1î", _
"<([dD]e)â", "\1î", _
"<([dD]es)â", "\1î", _
"<([dD]ez)â", "\1î", _
"<([eE]x)â", "\1î", _
"<([fF]oto)â", "\1î")
InlocuiriMultiple lista:=perechi, cu_meta:=True
' refacere cuvinte compuse <prefix>î - partea 2
perechi = Array("<([hH]iper)â", "\1î", _
"<([mM]icro)â", "\1î", _
"<([mM]ini)â", "\1î", _
"<([mM]ult)â", "\1î", _
"<([nN]e)â", "\1î", _
"<([nN]emai)â", "\1î", _
"<([nN]on)â", "\1î", _
"<([pP]rea)â", "\1î", _
"<([pP]re)â", "\1î", _
"<([pP]ro)â", "\1î", _
"<([pP]seudo)â", "\1î", _
"<([rR]" & ChrW(259) & "s)â", "\1î", _
"<([rR]e)â", "\1î", _
"<([sS]emi)â", "\1î", _
"<([sS]ub)â", "\1î", _
"<([sS]ubt)â", "\1î", _
"<([sS]uper)â", "\1î", _
"<([sS]upra)â", "\1î", _
"<([tT]ele)â", "\1î", _
"<([tT]ripla)â", "\1î", _
"<([uU]ltra)â", "\1î")
InlocuiriMultiple lista:=perechi, cu_meta:=True
MsgBox "Numarul total de cuvinte: " & ActiveDocument.Words.count & _
", timp de executie: " & Format(Round(Timer - timp, 3), "0.###") & " secunde", vbOKOnly, _
"Convert_In_Ortografie_Contemporana"
End Sub
'======================================================================
'======================================================================
' Executa o secventa de inlocuiri multiple in
' - tot textul documentului
' - toate notele de subsol
' - toate notele de final
' Parametri:
' - lista(): lista de perechi <de_inlocuit>, <inlocuitor>
' - cu_meta: Daca e True, inlocuirile se fac cu metacaractere (wildcards)
Private Sub InlocuiriMultiple(ByRef lista() As Variant, cu_meta As Boolean)
Dim orng As Range
'----------------------------
' activez setarile pentru optimizare viteza macro
Dim Opt1 As Boolean: Opt1 = Options.Pagination: Options.Pagination = False
Dim Opt2 As Boolean: Opt2 = Application.ScreenUpdating: Application.ScreenUpdating = False
'---------------------------
' executa inlocuirile in textul documentului
Set orng = ActiveDocument.Range: orng.Expand wdStory
InlocuiriMultiple_Range lista:=lista, rng:=orng, cu_meta:=cu_meta
'---------------------------
' executa inlocuirile in notele de final (Endnote)
If ActiveDocument.Endnotes.count > 0 Then
Set orng = ActiveDocument.Endnotes(1).Range: orng.Expand wdStory
InlocuiriMultiple_Range lista:=lista, rng:=orng, cu_meta:=cu_meta
End If
'---------------------------
' executa inlocuirile in notele de subsol (Footnote)
If ActiveDocument.Footnotes.count > 0 Then
Set orng = ActiveDocument.Footnotes(1).Range: orng.Expand wdStory
InlocuiriMultiple_Range lista:=lista, rng:=orng, cu_meta:=cu_meta
End If
'----------------------------
' optimizari de memorie
ActiveDocument.UndoClear
Set orng = Nothing
'----------------------------
' dezactivez setarile pentru marire viteza macro
Options.Pagination = Opt1
Application.ScreenUpdating = Opt2
End Sub
'======================================================================
'======================================================================
Private Sub InlocuiriMultiple_Range(ByRef lista() As Variant, rng As Range, cu_meta As Boolean)
Dim count As Long: count = UBound(lista)
With rng.Find
.ClearFormatting: .Replacement.ClearFormatting
.Format = False: .MatchCase = True
.MatchWildcards = cu_meta
.Replacement.Highlight = True 'sterge linia asta pentru a nu evidentia schimbarile
' fac toate inlocuirile din lista
For i = LBound(lista) To count Step 2
StatusBar = i / 2 & "/" & (count - 1) / 2 & " Inlocuire " & lista(i) & " cu " & lista(i + 1)
.text = lista(i): .Replacement.text = lista(i + 1): .Execute Replace:=wdReplaceAll
Next i
End With
End Sub
'====================================================================== |