Solved

Manually format a couple of terms within a paragraph using VBA

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
When creating Microsoft Word-based forms there may be a need to have a form field repeated throughout the whole document. For instance, with a company name, you may want this information repeated automatically throughout the document rather than man…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

910 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

25 Experts available now in Live!

Get 1:1 Help Now