|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Need help with modifying a replacing font VBA code- similar task but subtle change
I got help with a similar issue a while back (see post: https://www.msofficeforums.com/word-...acro-help.html) and the resulting code has worked great for my needs! However, I would like to add a second "clickable button" that would do a slightly different task and I haven't had much luck finding the right tweaks to the code to make it work.
What I am trying to do is to search the document and have any text that is "(insert xyzabc emoji)" become highlighted in yellow with the click of the button. The xyzabc will vary from time to time and could contain up to several words but it would always be couched between "(insert" and "emoji)". Hopefully there is an easy solution to this! Here is the code I have been working from. Any suggestions for edits are GREATLY appreciated!! --- Private Sub Colorize_Hashtags_Button_Click() ' Colorize_Hashtags Macro ' ' Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find.Replacement.Font .Underline = wdUnderlineSingle .Color = wdColorBlue End With With Selection.Find .Text = "\#[A-Z,a-z,0-9]@>" .Replacement.Text = "^&" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True End With Selection.Find.Execute Selection.Find.Execute Replace:=wdReplaceAll End Sub |
#2
|
|||
|
|||
Use
Code:
Selection.HomeKey wdStory Selection.Find.ClearFormatting With Selection.Find Do While .Execute(FindText:="\(insert * emoji\)", MatchWildcards:=True, Forward:=True, Wrap:=wdFindStop) = True With Selection If MsgBox("Click OK to colorize selection", vbOKCancel) = vbOK Then .Range.Shading.BackgroundPatternColor = wdColorYellow End If .Collapse wdCollapseEnd End With Loop End With |
#3
|
|||
|
|||
Just got around to this project again and the code works PERFECTLY!!! Thank you so much for the easy solution and quick help
|
#4
|
|||
|
|||
Okay this has been workign GREAT- sooooo pleased....
but hoping I can get help with one small tweak to the formula. When the Macro runs it stops at the end of the document and moves what I am viewing on the screen to the end as well. However, the original reference formula does it's thing without losing my place on the screen. Is there a way to edit this one to stay put? |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Displaying Code in a task usage view | ksa5024 | Project | 1 | 06-15-2016 06:15 PM |
Is there an option to choose font color when replacing text in Excel 2003? | chr2014 | Excel | 8 | 11-14-2014 09:13 PM |
Looping Macro to Change Font, Font Size, and Give Heading 1 | WH7262 | Word VBA | 1 | 08-26-2014 03:46 PM |
Make Font Dropdown Change All Styles' Font | trevorhiller | Word | 1 | 04-14-2012 02:14 AM |
modifying rule to show new mail envelope in task bar | mlov83 | Outlook | 5 | 02-11-2011 01:36 PM |