Link to home
Start Free TrialLog in
Avatar of Andreas Hermle
Andreas HermleFlag for Germany

asked on

Manually format a couple of terms within a paragraph using VBA

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

Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Guessing till I can validate but

New line 8 as

My range.font.size  = 10

Chris
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
Avatar of Andreas Hermle

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Chris,

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

Regards, Andreas