Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 09-05-2015, 09:19 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

Pass the values from the form to the macro e.g. as follows and unload the form when you have finished with it either as here or in the calling macro.

Code:
Private Sub cmdOK_Click()

    Dim SearchColor As Long
    Dim ReplaceColor As Long

    If OptYellow1 = True Then SearchColor = wdYellow
    If optBrightGreen1 = True Then SearchColor = wdBrightGreen
    If optTurquoise1 = True Then SearchColor = wdTurquoise
    If optPink1 = True Then SearchColor = wdPink
    If optBlue1 = True Then SearchColor = wdBlue
    If optRed1 = True Then SearchColor = wdRed
    If optDarkBlue1 = True Then SearchColor = wdDarkBlue
    If optTeal1 = True Then SearchColor = wdTeal
    If optGreen1 = True Then SearchColor = wdGreen
    If optViolet1 = True Then SearchColor = wdViolet
    If optDarkRed1 = True Then SearchColor = wdDarkRed
    If optDarkYellow1 = True Then SearchColor = wdDarkYellow
    If optGray501 = True Then SearchColor = wdGray50
    If optGray251 = True Then SearchColor = wdGray25
    If optBlack1 = True Then SearchColor = wdBlack
    
    If optYellow2 = True Then ReplaceColor = wdYellow
    If optBrightGreen2 = True Then ReplaceColor = wdBrightGreen
    If optTurquoise2 = True Then ReplaceColor = wdTurquoise
    If OptPink2 = True Then ReplaceColor = wdPink
    If optBlue2 = True Then ReplaceColor = wdBlue
    If optRed2 = True Then ReplaceColor = wdRed
    If optDarkBlue2 = True Then ReplaceColor = wdDarkBlue
    If optTeal2 = True Then ReplaceColor = wdTeal
    If optGreen2 = True Then ReplaceColor = wdGreen
    If optViolet2 = True Then ReplaceColor = wdViolet
    If optDarkRed2 = True Then ReplaceColor = wdDarkRed
    If optDarkYellow2 = True Then ReplaceColor = wdDarkYellow
    If optGray502 = True Then ReplaceColor = wdGray50
    If optGray252 = True Then ReplaceColor = wdGray25
    If optBlack2 = True Then ReplaceColor = wdBlack
    If optNoColor = True Then ReplaceColor = wdNoHighlight
    
    DoColorChange SearchColor, ReplaceColor
    Unload Me
End Sub

Private Sub cmdCancel_Click()
    Unload Me
End Sub

Private Sub DoColorChange(SearchColor As Long, ReplaceColor As Long)

Dim oDoc As Document
Dim oRng As Range
Dim intPosition As Long

Set oDoc = ActiveDocument
Set oRng = oDoc.Range

With oRng.Find
    .Highlight = True
    .Forward = True
    Do While oRng.Find.Execute
        If oRng.HighlightColorIndex = SearchColor Then
           oRng.HighlightColorIndex = ReplaceColor
        End If
        intPosition = oRng.End
        oRng.Start = intPosition
    Loop
End With

End Sub
__________________
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
 



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 01:34 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