Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-01-2016, 07:50 AM
kissingfrogs2003 kissingfrogs2003 is offline Need help with modifying a replacing font VBA code- similar task but subtle change Windows 7 64bit Need help with modifying a replacing font VBA code- similar task but subtle change Office 2016
Novice
Need help with modifying a replacing font VBA code- similar task but subtle change
 
Join Date: Jan 2016
Posts: 9
kissingfrogs2003 is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 07-06-2016, 11:33 PM
DougMVP DougMVP is offline Need help with modifying a replacing font VBA code- similar task but subtle change Windows 7 32bit Need help with modifying a replacing font VBA code- similar task but subtle change Office 2010 32bit
Advanced Beginner
 
Join Date: Nov 2013
Posts: 50
DougMVP will become famous soon enough
Default

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
If you just want the colorizing to happen without click OK each time, delete the If and EndIf lines, leaving the .Range.Shading.BackgroundPatternColor = wdColorYellow line.
Reply With Quote
  #3  
Old 08-02-2016, 12:07 PM
kissingfrogs2003 kissingfrogs2003 is offline Need help with modifying a replacing font VBA code- similar task but subtle change Windows 7 64bit Need help with modifying a replacing font VBA code- similar task but subtle change Office 2016
Novice
Need help with modifying a replacing font VBA code- similar task but subtle change
 
Join Date: Jan 2016
Posts: 9
kissingfrogs2003 is on a distinguished road
Default

Just got around to this project again and the code works PERFECTLY!!! Thank you so much for the easy solution and quick help
Reply With Quote
  #4  
Old 08-30-2016, 11:42 AM
kissingfrogs2003 kissingfrogs2003 is offline Need help with modifying a replacing font VBA code- similar task but subtle change Windows 7 64bit Need help with modifying a replacing font VBA code- similar task but subtle change Office 2016
Novice
Need help with modifying a replacing font VBA code- similar task but subtle change
 
Join Date: Jan 2016
Posts: 9
kissingfrogs2003 is on a distinguished road
Default

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?
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with modifying a replacing font VBA code- similar task but subtle change 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
Need help with modifying a replacing font VBA code- similar task but subtle change Looping Macro to Change Font, Font Size, and Give Heading 1 WH7262 Word VBA 1 08-26-2014 03:46 PM
Need help with modifying a replacing font VBA code- similar task but subtle change 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

Other Forums: Access Forums

All times are GMT -7. The time now is 11:37 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft