View Full Version : [SOLVED:] Macro to remove range of unicode characters
Simple
08-01-2022, 03:20 AM
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
Simple
08-01-2022, 10:31 AM
I will make it easier:
A simple replacement macro is like this:
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
Now, how can I change it to replace all the unicode values from ^u01000 to ^u01100?
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
Simple
08-01-2022, 11:08 AM
I found the solution by myself!
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
macropod
08-01-2022, 02:57 PM
Rather more efficient:
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
Paul_Hossler
08-06-2022, 01:35 PM
I found the solution by myself!
Best way to learn
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.