473,569 Members | 2,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5861

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 theWordApplicat ion as Word.Applicatio n
Dim theDocument as Word.Document

Try

' Create a new word application

theWordApplicat ion = New Word.Applicatio n

' Add a new document, based on this template

theDocument =
m_WordApplicati on.Documents.Ad d(Template:=CTy pe(__whatever_t he_template_it_ if_you_want_one __,
Object))

' Make the application invisible

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

' Add page numbers to the document.

Dim wordHeaderIndex As Word.WdHeaderFo oterIndex =
WdHeaderFooterI ndex.wdHeaderFo oterFirstPage

theWordApplicat ion.Sections.It em(1).Headers.I tem(wordHeaderI ndex).PageNumbe rs.Add
( _

PageNumberAlign ment:=
Word.WdPageNumb erAlignment.wdA lignPageNumberR ight, _
FirstPage:= True )

Catch Ex As Exception

' Failed.

Finally

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

Marshal.Release ComObject(theDo cument)
Marshal.Release ComObject(theWo rdApplication)

End Try
Nov 21 '05 #2

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

Similar topics

2
1938
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
6206
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 to solve their problem, I am having trouble coming up with the goods! + I would like to know the answer too.
28
14024
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
1985
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 be best performance-wise / maintenance wise. OR if there is another approach that is more commonly followed. I'm interested in performance mainly,...
1
2556
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 when you've done that, you have to know how to get those values back unless you've saved them somewhere for later retrieval. What I need is a way to...
1
2607
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? -- Thank you kindly, Dan Sikorsky BAB, BScE, MSC
7
6862
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 only problem with doing this is that a header (name of the page and Page x of x) and footer (actual page filename the date) are included. I am...
3
1949
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 best way. What i am doing is useing Response.write, so heres a example Function.vb...
0
1629
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 just wondering if there is a similar way of accomplishing this in a web form by inserting a CSS page break. Is there a way to roughly limit each...
0
7698
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7970
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.