![]() |
#2
|
||||
|
||||
![]()
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 |
|
![]() |
||||
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 |
![]() |
Lostinvba | Word VBA | 3 | 11-23-2013 07:22 PM |
![]() |
blockie | Mail Merge | 8 | 11-13-2013 11:28 PM |
![]() |
Zack | Excel | 2 | 10-14-2010 12:07 PM |
Trouble updating a form | TomCaesar | Outlook | 0 | 11-29-2006 10:52 AM |