Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Manually format a couple of terms within a paragraph using VBA

Posted on 2013-11-05
5
Medium Priority
?
265 Views
Last Modified: 2013-11-06
Dear Experts:

Below macro applies a user-defined paragraph style (MyStyle) to the term ...
... Table of Contents (clickable entries). The Style 'MyStyle' has 18pt as font size.

How is this macro to be re-written so that after applying the paragraph style, the term (clickable entries) is reformatted to just 10pt font size.

I could create a user-defined character style and apply that character style but as a matter of fact, the current macro should manually format this term ('clickable entries', i.e. including the brackets) in one go.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

Sub Apply_Style()
Dim myRange as Range

Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="Table of Contents (clickable entries)", Forward:=True
   If myRange.Find.Found = True Then
   myRange.Style = "My_Style"
   End If
End Sub

Open in new window

0
Comment
Question by:AndreasHermle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39624220
Guessing till I can validate but

New line 8 as

My range.font.size  = 10

Chris
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39624243
Yup

Sub Apply_Style()
Dim myRange As Range

Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="Table of Contents (clickable entries)", Forward:=True
   If myRange.Find.Found = True Then
       myRange.Style = "My_Style"
       myRange.Font.Size = 10
   End If
End Sub

Open in new window


Chris
0
 

Author Comment

by:AndreasHermle
ID: 39624404
Hi Chris,

thank you very much for your swift help.

My wording may have been a little bit confusing but ...
... I only would like part of this string to be reformatted to just 10 pt Font Size, ie. the part that says (cklickable entries).

The other part of the string, i.e. Table of Contents should retain its original style properties.

Regards, Andreas
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 39624680
Sub Apply_Style()
Dim myRange As Range

    Set myRange = ActiveDocument.Content
    myRange.Find.Execute FindText:="Table of Contents (clickable entries)", Forward:=True
    If myRange.Find.Found = True Then
        myRange.Style = "My_Style"
        myRange.Words(4).Font.Size = 10
        myRange.Words(5).Font.Size = 10
        myRange.Words(6).Font.Size = 10
        myRange.Words(7).Font.Size = 10
    End If
End Sub

Open in new window

0
 

Author Closing Comment

by:AndreasHermle
ID: 39626627
Hi Chris,

ok, this did the trick, thank you very much for your professional help.

Regards, Andreas
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question