Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-01-2015, 08:25 AM
Silvera Silvera is offline Can't Create a Macro that works Windows 7 64bit Can't Create a Macro that works Office 2010 64bit
Novice
Can't Create a Macro that works
 
Join Date: Jul 2013
Posts: 3
Silvera is on a distinguished road
Default Can't Create a Macro that works

I've been making macros for years in Office. I can not even make a simple macro in Word 2013 that my office switched to! I want to change some text color in some of my technical documents for clarity and or emphasis. I have followed (or at least I thought I did) the instructions on how to create a macro in Word. I want to be able to highlight a word or several words and change their color to Green and others to Blue and some to Red, for example. I realize that this would take 3 macros, one for each color.

This is what I do in Excel for changing cell(s) background color
Sub Green()
' Green Cell(s)
' Ctrl+Shift+G
' Macro edited 9/27/2008 by Steven Silvera
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 13434828
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End Sub

I know the above is not appropriate for Word.



Please let me know if you have a macro for Word that works similar
Reply With Quote
  #2  
Old 12-02-2015, 08:02 PM
macropod's Avatar
macropod macropod is offline Can't Create a Macro that works Windows 7 64bit Can't Create a Macro that works Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Are you trying to change the font colour, paragraph background colour, or the highlight colour? For highlighting possibilities, see:
https://www.msofficeforums.com/word-...html#post34948
https://www.msofficeforums.com/word-...html#post91282
https://www.msofficeforums.com/word-...html#post86501
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 12-02-2015, 08:13 PM
Silvera Silvera is offline Can't Create a Macro that works Windows 7 64bit Can't Create a Macro that works Office 2010 64bit
Novice
Can't Create a Macro that works
 
Join Date: Jul 2013
Posts: 3
Silvera is on a distinguished road
Default

The font color
Reply With Quote
  #4  
Old 12-02-2015, 11:15 PM
macropod's Avatar
macropod macropod is offline Can't Create a Macro that works Windows 7 64bit Can't Create a Macro that works Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

For that you could use something based on:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim StrFnd As String, i As Long
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Replacement.Text = "^&"
  .Forward = True
  .Format = True
  .Wrap = wdFindContinue
  .MatchCase = True
  .MatchWholeWord = True
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  StrFnd = "One,Two,Three"
  For i = 0 To UBound(Split(StrFnd, ","))
    .Text = Split(StrFnd, ",")(i)
    .Replacement.Font.ColorIndex = wdBlue
    .Execute Replace:=wdReplaceAll
  Next
  StrFnd = "Four,Five,Six"
  For i = 0 To UBound(Split(StrFnd, ","))
    .Text = Split(StrFnd, ",")(i)
    .Replacement.Font.ColorIndex = wdRed
    .Execute Replace:=wdReplaceAll
  Next
  StrFnd = "Seven,Eight,Nine,Ten"
  For i = 0 To UBound(Split(StrFnd, ","))
    .Text = Split(StrFnd, ",")(i)
    .Replacement.Font.ColorIndex = wdGreen
    .Execute Replace:=wdReplaceAll
  Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
macro



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro now fails in Word 2013 after working for more than a year; still works in 2007 cyraxote Word VBA 10 09-05-2015 12:33 AM
Looking for Help to Create a Macro (Sort) rsrasc Word VBA 5 04-16-2014 03:25 AM
Can't Create a Macro that works Macro works in Windows XP but not in Windows 7 Baldeagle Word VBA 3 09-30-2013 03:56 AM
macro works on windows, not on mac iiiiifffff Word VBA 2 04-03-2013 12:42 PM
Can't Create a Macro that works Why it works but the macro is error in VB? tinfanide Excel Programming 5 12-03-2011 12:53 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:13 AM.


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