Hi,
How can I make a macro that will remove from a selection all the characters in a unicode range?
For example, if I want to remove from a selection all the characters from unicode u01000 to unicode u01100?
Thank you very much
Printable View
Hi,
How can I make a macro that will remove from a selection all the characters in a unicode range?
For example, if I want to remove from a selection all the characters from unicode u01000 to unicode u01100?
Thank you very much
I will make it easier:
A simple replacement macro is like this:
Now, how can I change it to replace all the unicode values from ^u01000 to ^u01100?Code:Sub Replacement()
' Replacement Macro
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^u01000"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Maybe it could be done by creating a variable "n" with a value 01000 and after wdReplaceAll n=n+1, and adding a loop do while u<01101 . But how should I modify .Text = "^u01000" ? if I write "^u0n" I suppose it will not understand that n means my variable.
Thank you
I found the solution by myself!
Code:Sub Replacement()
' Replacement Macro
Sub Replacement()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Dim n As Integer
n = 1000
Do Until n > 1100
With Selection.Find
.Text = ChrW(n)
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
End With
Selection.Find.Execute Replace:=wdReplaceAll
n = n + 1
Loop
End Sub
Rather more efficient:
Code:Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Format = False
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.Text = "[" & ChrW(&H1000) & "-" & ChrW(&H109F) & "]"
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub