Word from VB.Net

A

Anne Richmond

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
 
J

Jeff Johnson [MVP: VB]

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.
 
J

Jan Hyde

"Anne Richmond" <[email protected]>'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.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

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)
 
G

Guest

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.
 

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