Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-06-2015, 09:36 PM
gmayor's Avatar
gmayor gmayor is offline userform help (having trouble passing info from form to macro) Windows 7 64bit userform help (having trouble passing info from form to macro) Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default


It ends at the end of the document. The macro works as written in Word 2010 and 2013. I didn't change anything in your macro except supply it with the parameters.

You can test it easily enough e.g.
Code:
Sub Macro1()
DoColorChange wdYellow, wdPink
End Sub
Personally I might have written it a little differently e.g.
Code:
Private Sub DoColorChange(SearchColor As Long, ReplaceColor As Long)

Dim oDoc As Document
Dim oRng As Range

Set oDoc = ActiveDocument
Set oRng = oDoc.Range

With oRng.Find
    .Highlight = True
    Do While oRng.Find.Execute
        If oRng.HighlightColorIndex = SearchColor Then
           oRng.HighlightColorIndex = ReplaceColor
        End If
        oRng.Collapse 0
    Loop
End With

End Sub
but it should work just the same as you had it.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #2  
Old 09-06-2015, 11:36 PM
cyraxote cyraxote is offline userform help (having trouble passing info from form to macro) Windows 7 64bit userform help (having trouble passing info from form to macro) Office 2013
Novice
userform help (having trouble passing info from form to macro)
 
Join Date: Sep 2015
Location: Essex, MD
Posts: 24
cyraxote is on a distinguished road
Default

I did the test as you suggested, and that got stuck in the endless loop, as did your alternate version. I'm using Word 2007, if that makes a difference.

My macro worked apart from the form when SearchColor and ReplaceColor were dimensioned as String, not Long. That's the only big difference I can see between this and the last working version. So I changed them back to strings:

Code:
Private Sub DoColorChange(SearchColor As String, ReplaceColor As String)

Dim oDoc As Document
Dim oRng As Range

Set oDoc = ActiveDocument
Set oRng = oDoc.Range

With oRng.Find
    .Highlight = True
    Do While oRng.Find.Execute
        If oRng.HighlightColorIndex = SearchColor Then
           oRng.HighlightColorIndex = ReplaceColor
        End If
        oRng.Collapse 0
    Loop
End With

End Sub
Sub Macro50()
    DoColorChange wdYellow, wdPink
End Sub
And this too causes the endless loop.

I went all the way back to the first one I posted, and now it TOO has the endless loop.

This is puzzling.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to copy cell info to multiple documents Patrick Innes Word VBA 2 02-18-2015 08:38 PM
userform help (having trouble passing info from form to macro) Trouble automatically running user form Lostinvba Word VBA 3 11-23-2013 07:22 PM
userform help (having trouble passing info from form to macro) I'm having trouble creating a Merge using label form and placing a shape in the text blockie Mail Merge 8 11-13-2013 11:28 PM
userform help (having trouble passing info from form to macro) Macro trouble Zack Excel 2 10-14-2010 12:07 PM
Trouble updating a form TomCaesar Outlook 0 11-29-2006 10:52 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:42 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