Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

VB.NET: Problem with Page header in Word Document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Balambikai N P - 09 Oct 2006 13:57 GMT
Hi,
I need to create page headers in a word document using VB.NET code.

The page header is different for odd and even pages. There are many odd page
section breaks in the document which splits the document into sections. For
all the sections, the odd page header should contain page number on left side
and the right side should display the name of a topic chosen within that
section with Heading style (1 to 5); this is provided by the user as command
line argument. The even page header should contain page number on right side
and document title on left side.

As the odd page has to automatically resolve the name of the topic with the
specified Heading style, I used  ActiveWindow.Selection.Fields.Add() method
with Text parameter as

"STYLEREF  ""Heading <n>"" "

<n> is the header level given by user through command line arguments.

Here is the code,

Select Case CType(topicTitleLevel, String)
Case 1
           titleHeaderLevel = "STYLEREF  ""Heading 1,h1"" "
Case 2
           titleHeaderLevel = "STYLEREF  ""Heading 2,h2"" "
Case 3
           titleHeaderLevel = "STYLEREF  ""Heading 3,h3"" "
Case 4
           titleHeaderLevel = "STYLEREF  ""Heading 4,h4"" "
Case 5
           titleHeaderLevel = "STYLEREF  ""Heading 5,h5"" "
Case Else
           titleHeaderLevel = "STYLEREF  ""Heading 2,h2"" "
End Select

Dim headerField As Field
'set the header text
headerField = m_wordDoc.ActiveWindow.Selection.Fields.Add( _
                 .Range,WdFieldType.wdFieldEmpty, titleHeaderLevel)

This code works fine. But inserts empty text in the header when there isn’t
any topic within the section with Heading <n> style chosen by the user.

Is there any way to modify the code to automatically pick the immediate
higher Heading style (e.g. it should pick Heading 3 style in case if there
isn’t any topic within that section with Heading 4 style) in only those
sections where it doesn’t have topics with required Heading levels?

Any pointers to resolve this would be appreciable.

Thanks in advance,
Bala
Shauna Kelly - 10 Oct 2006 23:25 GMT
Hi Balambikai N P

The following may help. I haven't tried it out, but the person who came up
with it was struggling with issues similar to yours:

http://groups.google.com.au/group/microsoft.public.word.docmanagement/browse_thr
ead/thread/75edec3265f57b71/f136ec54f4fbefad


Hope this helps.

Shauna Kelly.  Microsoft MVP.
http://www.shaunakelly.com/word

> Hi,
> I need to create page headers in a word document using VB.NET code.
[quoted text clipped - 56 lines]
> Thanks in advance,
> Bala
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.