Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-28-2014, 09:05 PM
McBanjo McBanjo is offline Macro for changing formatting of certain parts of a word Windows 7 64bit Macro for changing formatting of certain parts of a word Office 2013
Novice
Macro for changing formatting of certain parts of a word
 
Join Date: May 2014
Posts: 6
McBanjo is on a distinguished road
Question Macro for changing formatting of certain parts of a word

Hi Thread,

I have a really simple thing I want to do in Word 2013 Macros I'm sure, but having little knowledge of Macro scripting makes it difficult.

Here's the scenario. We have several products that have certain branding in a different font, two sizes larger than the standard Arial font and bolded. Easy enough, but the first few letters of the product name are also a different colour based on what product it is.

i.e. this:

abcphone
abcmobile
abcdesktop
abclaptop

to this:

abcphone
abcmobile


abcdesktop
abclatop


Here is something I've done so far:

Code:
Sub Branding()
'
' Branding Macro
'

   Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting
   With Selection.Find
        .Text = "abcphone"
        .Selection
        .Replacement.Text = ""
        .Replacement.Font.Bold = True
        .Replacement.Font.Name = "Myriad"
        .Forward = True
        .Wrap = wdFindContinue
        .MatchWholeWord = True
   End With
   Selection.Find.Execute Replace:=wdReplaceAll

End Sub
Any pointers on how to do this for every one of these words in a document? Any help would be greatly appreciated.
Reply With Quote
  #2  
Old 05-29-2014, 02:16 AM
macropod's Avatar
macropod macropod is offline Macro for changing formatting of certain parts of a word Windows 7 32bit Macro for changing formatting of certain parts of a word 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

Changing the font to bold, even to a different size and/or a different font, is easy enough - you don't even need a macro for that. But what are the criteria for the colour changes?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-29-2014, 03:51 PM
McBanjo McBanjo is offline Macro for changing formatting of certain parts of a word Windows 7 64bit Macro for changing formatting of certain parts of a word Office 2013
Novice
Macro for changing formatting of certain parts of a word
 
Join Date: May 2014
Posts: 6
McBanjo is on a distinguished road
Default

I'm just looking for a way to do it to every word on the page automatically for several words at a time by clicking a macro shortcut button to save time.

The criteria is that the first 2 letters of the selected word are in one specified colour and the rest of the letters are to remain in black. Also the font needs to be increased by two points and I'm not sure how to do that, i.e. from 10->12 or 12->14. Because the particular font is a bit smaller than normal typefaces.
Reply With Quote
  #4  
Old 05-29-2014, 04:05 PM
macropod's Avatar
macropod macropod is offline Macro for changing formatting of certain parts of a word Windows 7 32bit Macro for changing formatting of certain parts of a word 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

Fine, but what are the colouring criteria? Besides which, your first post indicated three letters with different colouring, now you say it's two...

There also seems to be some scope creep happening - you now also want the point size increased - which you didn't mention in your first post. Are there any other changes?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 05-29-2014, 04:10 PM
McBanjo McBanjo is offline Macro for changing formatting of certain parts of a word Windows 7 64bit Macro for changing formatting of certain parts of a word Office 2013
Novice
Macro for changing formatting of certain parts of a word
 
Join Date: May 2014
Posts: 6
McBanjo is on a distinguished road
Default

Haha, my apologies.

I was trying to keep it easy to explain and also hide the actual brands for privacy. So I slightly altered what I actually required with the view to changing it myself. It is code after all.

I need the colours to be changed to RGB values. e.g. 79,109,94 or 198,96,5
Reply With Quote
  #6  
Old 05-29-2014, 04:40 PM
macropod's Avatar
macropod macropod is offline Macro for changing formatting of certain parts of a word Windows 7 32bit Macro for changing formatting of certain parts of a word 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

You still haven't answered the most basic questions as to the criteria:
1. How does the code determine what letters to colour; and
2. What colour to make them.
Telling me they colours have RGB values (as all do) doesn't tell me what determines when a particular colour is to be used.

Re 1, for example, your first post seems to suggest the words all start with a particular letter sequence (abc). If you want the be able to specify the staring sequence, fine, but you need to say so. I don't want to waste my time coding for 'abc' when it isn't that at all and could be any number of different strings.

Re 2, for example, your first post suggests the colours may be linked to whatever the words end with. If so, you need to say so. It's no good me guessing.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 05-29-2014, 05:07 PM
McBanjo McBanjo is offline Macro for changing formatting of certain parts of a word Windows 7 64bit Macro for changing formatting of certain parts of a word Office 2013
Novice
Macro for changing formatting of certain parts of a word
 
Join Date: May 2014
Posts: 6
McBanjo is on a distinguished road
Default

Hmmmm, it's really tricky for me to conceptualise how to code this because I'm completely not accustomed to coding.

Let's pretend that 'abc' is 'ab' so it's only two letters then.

1. I'm not sure how it does. Could make it select the word 'abphone' then choose the first two letters, or select the word 'abphone' then find 'ab' within that selection then change the colour. Either would work. The colour is based on what the whole worded product name is as my first post says.

2. The colours that they are is irrelevant. I can change this myself. I'm just looking for a good template that I can add and remove products from. Make "abphone" orange, "abmobile" yellow, "abdesktop" green and "ablaptop" pink.

Appreciate any help given
Reply With Quote
  #8  
Old 05-29-2014, 07:07 PM
macropod's Avatar
macropod macropod is offline Macro for changing formatting of certain parts of a word Windows 7 32bit Macro for changing formatting of certain parts of a word 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

You are making it difficult for anyone to help you. You seem determined to not answer very plain questions.

The answer to both questions is vital. I asked you for two criteria and all you come back with is "I'm not sure how it does" and "The colours that they are is irrelevant".

Re 1: If you have no basis for deciding either of these things, how do you suppose a macro is going to do it????

Re 2: Crap. I'm not asking these things for my own amusement.

Programming works according to rules, not "I'm not sure how it does" and "The colours that they are is irrelevant".

As for "I'm just looking for a good template that I can add and remove products from", nothing of what has been discussed so far has anything to do with templates or adding/removing items. The only things that have been discussed concern font attributes.

Try the following. But until you can come back with something concrete, I'm not prepared to waste more time on this.
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim StrTxt As String, Rng As Range
StrTxt = InputBox("What are the *starting* letters to Find")
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "<" & StrTxt & "*>"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    With .Duplicate
      .Font.Size = .Font.Size + 2
      .Font.Bold = True
      Select Case Split(.Text, StrTxt)(1)
        Case "phone"
          .End = .Start + Len(StrTxt)
          .Font.ColorIndex = wdDarkYellow
        Case "mobile"
          .End = .Start + Len(StrTxt)
          .Font.ColorIndex = wdYellow
        Case "desktop"
          .End = .Start + Len(StrTxt)
          .Font.ColorIndex = wdGreen
        Case "laptop"
          .End = .Start + Len(StrTxt)
          .Font.ColorIndex = wdPink
      End Select
    End With
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 05-29-2014, 07:34 PM
McBanjo McBanjo is offline Macro for changing formatting of certain parts of a word Windows 7 64bit Macro for changing formatting of certain parts of a word Office 2013
Novice
Macro for changing formatting of certain parts of a word
 
Join Date: May 2014
Posts: 6
McBanjo is on a distinguished road
Default

No one is asking you to waste your time. No one is forcing you to do anything. If it's too difficult to communicate effectively with a beginner, don't. I would rather wait for someone with some level of communication skills to ask questions so as to be understood - not the consistent rudeness you display.

1. I'm asking for someone to tell me how code would do it. I honestly don't know. It's completely allowable for me to say I do not know. I gave several examples, the best I could do, so someone might think and be a bit creative and work it out. If it's wrong, big deal. I can work out the last bit. Just be thankful you're not taking briefs for paid work. Maybe you should seek to understand before declaring someone's incompetence or deliberate attempts to be difficult.

2. Inserting "red" is just as easy as inserting "insert your colour choice here", people do it all the time in code examples. You are asking because you want to do the complete lot of work. It's not important! This is also a legitimate response. You're saying you're not asking these questions for your own amusement, BUT YOU ARE!

I'm taking about the code. It's a template for code. It's what I'm seeking. I'm seeking a template of code, that I can chop and change into something I can use. That is what a template is.

Nevertheless thank you for your contribution, I'm sure I can work it out from here.
Reply With Quote
  #10  
Old 05-29-2014, 07:42 PM
macropod's Avatar
macropod macropod is offline Macro for changing formatting of certain parts of a word Windows 7 32bit Macro for changing formatting of certain parts of a word 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

I don't find it all difficult to communicate with beginners - take even a few nanoseconds to check out my 8,000+ posts here or my 20,000+ posts on other forums and you'll soon recognise that. That should also give you a fair idea of where the problem lays.

Read my questions again, then your replies. Ask yourself - which questions have been answered.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 12-18-2014, 09:23 PM
McBanjo McBanjo is offline Macro for changing formatting of certain parts of a word Windows 7 64bit Macro for changing formatting of certain parts of a word Office 2013
Novice
Macro for changing formatting of certain parts of a word
 
Join Date: May 2014
Posts: 6
McBanjo is on a distinguished road
Default

How could this be translated to work in Outlook 2013? The code works brilliantly. I've tried adding the Word reference library, but it doesn't seem to play.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro for changing formatting of certain parts of a word Need macro to merge files in Word and preserve formatting Carolin Word VBA 3 12-14-2014 04:01 AM
Macro for changing formatting of certain parts of a word Formatting Painter Issues - Changing Font Styles in .dot Jgreer0315 Word 12 02-06-2014 05:07 PM
Using Quick Parts >> Ref >> Field (Third word changing font) sonny49 Word 1 01-07-2014 10:01 AM
Macro for changing formatting of certain parts of a word Formatting changing constantly in Word sitash Word 1 04-16-2013 02:47 AM
Macro for changing formatting of certain parts of a word Formatting changing randomly Franuzz Word 1 07-14-2011 04:12 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:05 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