philbullock1223
Registered User.
- Local time
- Today, 17:11
- Joined
- Dec 31, 2011
- Messages
- 55
I am trying to export values in an Access Table to Word. Some of the items are headers and some are body paragraphs.
The code:
The code above works unless there are weird characters or empty paragraphs and then it starts to get off down the line. I guess Word counts characters and paragraphs differently with its Statistic commands then I would have expected.
This Range Start/End is confusing me. I just want to be able to post my Header with a Header style, and my body with a body style... one after another.... and I have a few hundred in a loop.
Is there a simpler way to post text within a word document without computing the Range like I am?......
The code:
Code:
'Code is located in a loop but simplified for this post
'Code to insert the Header
Cursor = wdDoc.ComputeStatistics(wdStatisticCharactersWithSpaces) + _
wdDoc.ComputeStatistics(wdStatisticParagraphs)
With wdDoc.Range(Start:=Cursor, End:=Cursor + 1)
.ParagraphFormat.Alignment = wdAlignParagraphLeft
.Style = "Heading 1"
.InsertAfter Section1.Header
.InsertParagraphAfter
End With
'Code to insert the Footer
Cursor = wdDoc.ComputeStatistics(wdStatisticCharactersWithSpaces) + _
wdDoc.ComputeStatistics(wdStatisticParagraphs)
With wdDoc.Range(Start:=Cursor, End:=Cursor + 1)
.ParagraphFormat.Alignment = wdAlignParagraphLeft
.Style = "Normal"
.InsertAfter Section1.Body
.InsertParagraphAfter
End With
The code above works unless there are weird characters or empty paragraphs and then it starts to get off down the line. I guess Word counts characters and paragraphs differently with its Statistic commands then I would have expected.
This Range Start/End is confusing me. I just want to be able to post my Header with a Header style, and my body with a body style... one after another.... and I have a few hundred in a loop.
Is there a simpler way to post text within a word document without computing the Range like I am?......