View Single Post
 
Old 09-05-2015, 09:19 PM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit 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