![]() |
|
#1
|
||||
|
||||
![]() Try: Code:
Sub Demo() Dim Rng As Range: Set Rng = Selection.Range With Selection With .Find .ClearFormatting .Replacement.ClearFormatting .Replacement.Text = "" .Format = False .Forward = False .Wrap = wdFindContinue .MatchWildcards = False .Text = "+" .Execute End With If .Find.Found Then Rng.Start = .Start Rng.Characters.First.Delete Rng.Style = "Emphasis" End If End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#2
|
|||
|
|||
![]()
You need to be careful with the word 'forward' and 'backward'. With Moveuntil 'Forward' means towards the end of the document, 'Backwards' vice versa.
Hence if you place the cursor at the end of the text and search forwards it will move 0 characters because it cannot go any further 'Forward'. The other point to consider is if you were using 'Option explicit' or not. If you weren't then wdForeward would be created as a new word variable of type variant and assigned the value 0 rather than being treated as typographical error (. Hence your use of wdForeward is a request to move forward 0 characters which is exactly the action you got. Additionally, if you'd checked the token wdForeward in the object browser you would have found it didn't exist. Lesson learned 1. Always always always use option explicit 2. Read the VBA word object model help pages very very carefully. |
![]() |
Tags |
comment, moveuntil, word hangs |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Word hangs completely when editing punctuation | cydevil | Word | 4 | 11-24-2016 04:16 PM |
![]() |
pintree3 | Office | 5 | 04-14-2014 02:27 PM |
![]() |
KevinJ | Word VBA | 2 | 11-05-2012 01:27 PM |
![]() |
pstein | Word | 2 | 03-31-2012 05:31 AM |
Hyperlink Look In Hangs Word 2010 | drumms | Word | 0 | 02-24-2012 11:35 AM |