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
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?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
Last edited by Aussiebear; 08-01-2022 at 01:08 PM. Reason: Added code tags to supplied code
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
Last edited by Aussiebear; 08-01-2022 at 01:07 PM. Reason: Added code tags to supplied code
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
Cheers
Paul Edstein
[Fmr MS MVP - Word]
---------------------------------------------------------------------------------------------------------------------
Paul
Remember: Tell us WHAT you want to do, not HOW you think you want to do it
1. Use [CODE] ....[/CODE ] Tags for readability
[CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
2. Upload an example
Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
3. Mark the thread as [Solved] when you have an answer
Thread Tools (on the top right corner, above the first message)
4. Read the Forum FAQ, especially the part about cross-posting in other forums
http://www.vbaexpress.com/forum/faq...._new_faq_item3