473,395 Members | 1,696 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,395 software developers and data experts.

Headers and footers

I am trying to save and print reports of calculations of a program that make
adjustments. Doing that for a Word Document is fine because we can format the
text from VB .NET.

I have already all the results in a word document, but I would like to put a
Header and a Footer and page numbers on the document. However I don’t have
the finest idea how to make that!!

From VBA I can do that, but the instructions that put Header and Footer
automatically in VBA don’t work in VB .NET.

Do anyone now's how to do this from VB .NET?

Thanks

Nov 21 '05 #1
1 5824

First, you need to get a reference to the word document, then you just use
the automation stuff as you would with VBA, but with some VB.NET syntax.
This example will create a new document and add peage numbers to the header,
aligned to the right. Make sure you add a reference to the Word object
library to your project and import the library at the top of your code.
btw: Word documents have headers and footers by default, they are just not
visible :).
Imports System.Runtime.InteropServices
Imports Word
Dim theWordApplication as Word.Application
Dim theDocument as Word.Document

Try

' Create a new word application

theWordApplication = New Word.Application

' Add a new document, based on this template

theDocument =
m_WordApplication.Documents.Add(Template:=CType(__ whatever_the_template_it_if_you_want_one__,
Object))

' Make the application invisible

theWordApplication.Visible = False ' Make this true to see results while
debugging

' Add page numbers to the document.

Dim wordHeaderIndex As Word.WdHeaderFooterIndex =
WdHeaderFooterIndex.wdHeaderFooterFirstPage

theWordApplication.Sections.Item(1).Headers.Item(w ordHeaderIndex).PageNumbers.Add
( _

PageNumberAlignment:=
Word.WdPageNumberAlignment.wdAlignPageNumberRight, _
FirstPage:= True )

Catch Ex As Exception

' Failed.

Finally

' One thing about Interop, always Try/Catch and cleanup references.

Marshal.ReleaseComObject(theDocument)
Marshal.ReleaseComObject(theWordApplication)

End Try
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Web Surfer | last post by:
www.authoring.stylesheets] Is it possible to use stylesheets to override the Headers and Footers that are displayed on a printed webpage ?
2
by: Rupe | last post by:
Hi CSS gurus! I have an embarassing problem. I am a php programmer and I try to expound the advantages of css on the php newsgroups. However, after telling someone that they should use css...
28
by: reneecccwest | last post by:
hello, how can I remove IE headers and footers when I print a page? I'd like to use a code to remove them, not thru the IE page setup. s/RC
3
by: Chris Transcend | last post by:
Hi all, I'm writing my first .NET website and am wondering what the best method for including headers and footers is. I was thinking either a user or server control but am not sure which would...
1
by: Kenneth | last post by:
Hi, In IE6 you can configure output to the printer getting a clean printout only with content, but without headers and footers. You remove the Header and Footer content from the Page Setup. But...
1
by: Dan Sikorsky | last post by:
Under the File menu, Page Setup item in the IE is a way to setup the Page headers and footers the show when you print a page in the browser. How can we set those programmatically in a webform? ...
7
by: Robert Adkison | last post by:
I need to print a web page. It is my preference that my users just do a File/Print from explorer. That way my users will get the print dialog that will allow them to select the fax printer. The...
3
by: Dessip | last post by:
Hey, this is probbly a really simple answer, but im useing ASP.NET V1.1 and im trying to create a dynamic header, but a static footer. But i dont want to use place holders. thou its probbly the...
0
by: steve | last post by:
I am looking for a way to create dynamic headers and footers in a web form. There are .Net PDF products that convert web form content into PDF format and insert dynamic headers/footers. I'm...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.