PDA

View Full Version : [SOLVED:] Select "Heading 1" Paragraph text



Peeps
04-25-2010, 12:03 PM
Forgive me for asking for what may seem a stupidly simple question.

I can find paragraphs throughout a document using


With ActiveDocument
For Each p In .Paragraphs
If p.Style = "Heading 1" Then... etc.

However I'm having difficulty selecting the "Heading 1" text to copy to put into the Header.

Any suggestions?
Polite answers please!

Peeps

mdmackillop
04-25-2010, 12:50 PM
If p.Style = "Heading 1" Then
txt = p.Range.Text
End If

Peeps
04-25-2010, 12:53 PM
Fantastic!

Thank You

Peeps

Peeps
04-25-2010, 01:20 PM
If p.Style = "Heading 1" Then
txt = p.Range.Text
End If

I tried running the following macro within a word document just to check the text.


Dim txt As Range
Dim p As Paragraph
With ActiveDocument
For Each p In .Paragraphs
If p.Style = "Heading 1" Then
txt = p.Range.Text
MsgBox "text is " & txt
End If
Next p
End With

I got the following error

Run-time error '91'
Object variable or With block variable not set

Any further suggestions?

mdmackillop
04-25-2010, 03:24 PM
Dim txt As String

Peeps
04-25-2010, 03:36 PM
Cheers

Peeps