Populating blank sections

A

Arry Potter

Hi All,

I have a word document with standard heading and sub heading
sections.I wanted to write a macro which could populate the corresponding
heading or subheading sections with some standard text.The only clause is
that when heading is blank , I want the population to occur. else it must
not touch the section.

Current Document

1 Heading
blank
1.1 Subheading
not blank

After Running the Macro

1 Heading
Its a heading <change>
1.1 Subheading
not blank <no change>
 
A

Arry Potter

My Configuration is word 2003, Win Xp and I have posted this in foll
newsgroup(programming,general and new users). Just want to see some quick
response as I need to get back to my customers on this.
 
O

old man

Hi Arry,

There are three possible headers associated with a section
(wdHeaderFooterEvenPages, wdHeaderFooterFirstPage,wdHeaderFooterPrimary) but
I am just checking the primary header. All headers default to a chr (13) and
if you want to you can change to code to trim the header before checking the
length.

Sub f1()
Dim section1 As Section
Dim str1 As String

For Each section1 In ActiveDocument.Sections

str1 = section1.Headers(wdHeaderFooterPrimary).Range.Text
If Len(str1) = 1 And Asc(str1) = 13 Then
section1.Headers(wdHeaderFooterPrimary).Range.Text = "Sample Text"
End If

Next

End Sub

Old Man
 
R

Russ

Ey Arry,
Insert Autotext entries that consist of formatted boilerplate text and
images, etc. Also Mail Merge Methods. Unless you are dynamically creating
the text that you want inserted.
Are your headings formatted with a particular list style? Just search for
two paragraphs in a row with the same list style.

Get clues from this link:
 
R

Russ

Arvind,
See if this subroutine does what you want.


Public Sub FindNoDataLocation()
Dim myDoc As Word.Document
Dim aParagraph As Word.Paragraph
Dim aRange As Word.Range

Set myDoc = ActiveDocument
For Each aParagraph In myDoc.Paragraphs
If InStr(aParagraph.Style, "Heading 1") <> 0 _
Or InStr(aParagraph.Style, "Heading 2") <> 0 Then
Set aRange = aParagraph.Range
aRange.Move Unit:=wdParagraph, Count:=1
aRange.Expand Unit:=wdParagraph
If aRange.Characters.Count = 1 Then
aRange.Collapse
aRange.InsertBefore "TBC"
aRange.Font.Animation = wdAnimationMarchingRedAnts
ElseIf InStr(aRange.Paragraphs(1).Style, "Heading ") <> 0 Then
Set aRange = aParagraph.Range
aRange.Collapse Direction:=wdCollapseEnd
aRange.Move Unit:=wdCharacter, Count:=-1
aRange.Select
With Selection
.TypeParagraph
.TypeText "TBC"
.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
End With
Set aRange = Selection.Range
aRange.Font.Animation = wdAnimationMarchingRedAnts
End If
End If
Next aParagraph
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