473,323 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Word from VB.Net

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
3 4801

"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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
3
by: Yohancef Chin | last post by:
Hi, Being fairly new to .NET I am looking for a way to call MS Word from an event on a webform, and after the user is finished save that created document to an SQL Server database. Has anyone...
2
by: Mikey | last post by:
Sample VB .NET source code to create mailing labels or customized letters using MS Word MailMerge This VB .NET source code will start MS Word and call methods and set properties in MS Word to...
7
by: Dave | last post by:
Apologies for the newbie question. I have created a vb.net program for my company that is designed to work with Word Templates (about forty of them that we commonly use) that are selected by the...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
1
by: beanie | last post by:
i am a c programming beginner and i am trying to Create a concordance of Word Count for a text File in c programming but my code isn't working.please can u help me out.here is my code: #include...
2
by: beanie | last post by:
i am a beginer in c programming and i am trying to Create a Concordance of Word Count for a Text File but my code is not working.pls can anyone helpme out.here is my code: #include <stdio.h>...
0
by: alivip | last post by:
I write code to get most frequent words in the file I won't to implement bigram probability by modifying the code to do the following: How can I get every Token (word) and ...
5
by: alivip | last post by:
How can I get every Token (word) and PreviousToken(Previous word) From multube files and frequency of each two word my code is trying to get all single word and double word (every Token (word) and...
1
by: dittytwo | last post by:
Hi there The below code works if you don't try to do anything to the word document which is great (Not :D) I am having problems with the context command both text (i.e initial document with no...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.