Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-15-2017, 11:17 PM
macropod's Avatar
macropod macropod is offline Word hangs when MoveUntil is used and Comment present Windows 7 64bit Word hangs when MoveUntil is used and Comment present Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default


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
Replace 'Emphasis' with your Style name.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 11-16-2017, 02:36 AM
slaycock slaycock is offline Word hangs when MoveUntil is used and Comment present Windows 7 64bit Word hangs when MoveUntil is used and Comment present Office 2016
Expert
 
Join Date: Sep 2013
Posts: 255
slaycock is on a distinguished road
Default

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.
Reply With Quote
Reply

Tags
comment, moveuntil, word hangs



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word hangs completely when editing punctuation cydevil Word 4 11-24-2016 04:16 PM
Word hangs when MoveUntil is used and Comment present How to make Office (Word) 2010 stick to the present task pintree3 Office 5 04-14-2014 02:27 PM
Word hangs when MoveUntil is used and Comment present VBA equivalent to selecting present word KevinJ Word VBA 2 11-05-2012 01:27 PM
Word hangs when MoveUntil is used and Comment present How to insert a (balloon) comment and how to disable comment feature in Word2007? pstein Word 2 03-31-2012 05:31 AM
Hyperlink Look In Hangs Word 2010 drumms Word 0 02-24-2012 11:35 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:00 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft