Creating a format for headers

S

Stork

I would like to create a format in word that makes it possible to transfer a
word from the text to a header. For example, if I write:

"This is my header"

in the text, I would like to be able to mark that text and chose a format
which automatically converts that text into a header.

Does anyone understand what I mean? And if so, is it possible?
 
G

Greg Maxey

I am not sure that I understand what you mean. The following will take
selected text in the document and put it in the headers as centered red
text. Perhaps you can adapt to your needs.


Sub ScratchMacro()
Dim oDoc As Document
Dim oRng As Word.Range
Dim myHdrText As String
Dim i As Long
Set oDoc = ActiveDocument
myHdrText = Selection.Text
With oDoc.Sections(1)
For i = 1 To 3
With .Headers(i)
Set oRng = .Range
With oRng
.Delete
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Text = myHdrText
.Font.Color = wdColorRed
End With
End With
Next i
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top