Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

word 2010 vba how to set highlighted text to heading 2 or 3 1

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
0
36
US
I want to highlight some text and click a button on the quick access tool bar instead of drilling down through the headings.
I can't seem to find anything so I have no idea where to start with an code.

TIA

DougP
 
And what say the macro recorder when you do this manually ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
the macro recorder created this:

Selection.Style = ActiveDocument.Styles("Heading 2")

which I extrapalated into this:

Public Sub ChangeHeading2()
'change already selected text to Heading 2
With Selection
.Style = ActiveDocument.Styles("Heading 2")
End With
End Sub

So

DougP
 
Code:
Public Sub ChangeHeading2()
  'change already selected text to Heading 2
  Selection.Style = ActiveDocument.Styles("Heading 2")
End Sub
So why is it not working?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
This is a twist to make one procedure to...

1) change any selection that is Heading 2 to Heading 3

2) change any selection that is Heading 3 to Normal

3) change any selection that is neither Heading 2 or Heading 3 to Heading 2
Code:
Sub test()
    Select Case Selection.Style
        Case "Heading 2"
            Selection.Style = ActiveDocument.Styles("Heading 3")
        Case "Heading 3"
            Selection.Style = ActiveDocument.Styles("Normal")
        Case Else
            Selection.Style = ActiveDocument.Styles("Heading 2")
    End Select
End Sub


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Ooohhh Cool Skip, I like that since I am not sure which one I want.

have a Star [yoda]


DougP
 
Word has built-in keyboard shortcuts. No VBA required. They apply to the current paragraph.

Alt-Ctrl-1 = Heading 1
Alt-Ctrl-2 = Heading 2
Alt-Ctrl-3 = Heading 3
Ctrl-Shift-N = Normal

Gerry
 
Jerry, the Word Master, has enlightened me!

Back from the woods?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top