![]() |
#1
|
|||
|
|||
![]()
The purpose of the form and macro is to allow the user to search for text highlighted in one color and change it to another color or no color.
This is the form: ![]() This is the code: Code:
Option Explicit Private Sub cmdOK_Click() Dim SearchColor As String Dim ReplaceColor As String 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 End Sub Private Sub cmdCancel_Click() Unload Me End Sub Private Sub DoColorChange() Dim oDoc As Document Dim oRng As Range Dim intPosition As Long 'Dim SearchColor As String 'Dim ReplaceColor As String 'SearchColor = wdYellow 'ReplaceColor = wdDarkBlue 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 1) If the Dim statements for SearchColor and ReplaceColor in DoColorChange are commented out (as above), I get "Compile error: Variable not defined." 2) If those Dim statements are active, I get "Run-time error '13': Type mismatch. I'm not really sure where to define those variables (OK button code? macro?), what to define them as (since there's no type mismatch outside the form), and how to get the information from the form to the macro. If I put a breakpoint at If optNoColor = True Then ReplaceColor = wdNoHighlightI can hover the mouse and see that the variables for the colors I select in the form are true, and the others are false, so I'm fairly certain that code is OK. I've been fiddling with this for hours, so I think I'm officially stumped. Any help would be greatly appreciated. |
|
![]() |
||||
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 |