Solved

Manually format a couple of terms within a paragraph using VBA

Posted on 2013-11-05
5
260 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
  • 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 500 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Numerous files can not be opened anymore 17 64
VBA code snippets in a Word 2016 document 3 81
Recursion / Iteration in Word 2013 Mail Merge 16 73
Need a poor man's PowerPoint 5 105
Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

776 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