Solved

Manually format a couple of terms within a paragraph using VBA

Posted on 2013-11-05
5
258 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now