By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,578 Members | 1,800 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,578 IT Pros & Developers. It's quick & easy.

Word from VB.Net

P: n/a
The following code creates a word document.

How do I add a footer to each page containing the date and page number?

Dim wrdApp As Word.Application

Dim wrdDoc As Word.Document

Dim wrdSelection As Word.Selection

Dim mText As String

Dim mSub As Integer

wrdApp = CreateObject("Word.Application")

wrdDoc = wrdApp.Documents.Add()

wrdDoc.Select()

wrdSelection = wrdApp.Selection

wrdSelection.ParagraphFormat.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphCenter

wrdSelection.TypeText("New Cases")

wrdSelection.TypeParagraph()

wrdSelection.ParagraphFormat.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphLeft

wrdSelection.TypeParagraph()

wrdSelection.TypeParagraph()

For mSub = 0 To 50

mText = "Line " & mSub

wrdSelection.TypeText(mText)

wrdSelection.TypeParagraph()

Next

wrdApp.Visible = True


Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"Anne Richmond" <an***********@bradford.gov.uk> wrote in message
news:bs********************@karoo.co.uk...
The following code creates a word document.

How do I add a footer to each page containing the date and page number?


If you don't get an answer here I recommend asking in one of the
microsoft.public.word.vba.* groups. They'd know exactly what code to use.
Nov 21 '05 #2

P: n/a
"Anne Richmond" <an***********@bradford.gov.uk>'s wild
thoughts were released on Tue, 28 Sep 2004 15:17:06 +0100
bearing the following fruit:
The following code creates a word document.

How do I add a footer to each page containing the date and page number?

Dim wrdApp As Word.Application

Dim wrdDoc As Word.Document

Dim wrdSelection As Word.Selection

Dim mText As String

Dim mSub As Integer

wrdApp = CreateObject("Word.Application")

wrdDoc = wrdApp.Documents.Add()

wrdDoc.Select()

wrdSelection = wrdApp.Selection

wrdSelection.ParagraphFormat.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphCente r

wrdSelection.TypeText("New Cases")

wrdSelection.TypeParagraph()

wrdSelection.ParagraphFormat.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphLeft

wrdSelection.TypeParagraph()

wrdSelection.TypeParagraph()

For mSub = 0 To 50

mText = "Line " & mSub

wrdSelection.TypeText(mText)

wrdSelection.TypeParagraph()

Next

wrdApp.Visible = True


I know very little about word in this respect but a little
playing around

wrdApp.Visible = True
If wrdDoc.ActiveWindow.ActivePane.View.Type =
Word.WdViewType.wdNormalView Or
wrdDoc.ActiveWindow.ActivePane.View.Type =
Word.WdViewType.wdOutlineView Then
wrdDoc.ActiveWindow.ActivePane.View.Type =
Word.WdViewType.wdPrintView
End If
wrdDoc.ActiveWindow.ActivePane.View.SeekView =
Word.WdSeekView.wdSeekCurrentPageFooter
wrdApp.Selection.Fields.Add(wrdApp.Selection.Range ,
Word.WdFieldType.wdFieldDate)
wrdApp.Selection.Fields.Add(wrdApp.Selection.Range ,
Word.WdFieldType.wdFieldPage)

However, I always suggest that you record a macro in word
then do whatever it is you require and look at the code that
is produced. Usually the generated code can easily be used
in your VB app.

Playing around with the activepane can be (excuse the pun) a
real pain

Jan Hyde (VB MVP)

--
Did you hear about the group of geometry teachers who started a motorcycle club?
Hell's Angles. (KM)

[Abolish the TV License - http://www.tvlicensing.biz/]

Nov 21 '05 #3

P: n/a
You might go to Word and record a macro for creating a footer. You can view
the resulting Macro VBA code and probably get some good ideas on how to do it.

"Anne Richmond" wrote:
The following code creates a word document.

How do I add a footer to each page containing the date and page number?

Dim wrdApp As Word.Application

Dim wrdDoc As Word.Document

Dim wrdSelection As Word.Selection

Dim mText As String

Dim mSub As Integer

wrdApp = CreateObject("Word.Application")

wrdDoc = wrdApp.Documents.Add()

wrdDoc.Select()

wrdSelection = wrdApp.Selection

wrdSelection.ParagraphFormat.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphCenter

wrdSelection.TypeText("New Cases")

wrdSelection.TypeParagraph()

wrdSelection.ParagraphFormat.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphLeft

wrdSelection.TypeParagraph()

wrdSelection.TypeParagraph()

For mSub = 0 To 50

mText = "Line " & mSub

wrdSelection.TypeText(mText)

wrdSelection.TypeParagraph()

Next

wrdApp.Visible = True


Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.