Hi,

I need your help desperately. I've been trying to get this to work since
yesterday but to no avail. I was trying to insert Header/Footer using VBA in
word 03. This will involve section breaks insertion into the document.

My problem is i think i haven't really put the following code in the right
place.
Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
LinkToPrevious

Different Sections will have different Header and Footer in the document.

Here is my code of inserting a section of "Bibliography" into the document.
This might be placed in the middle of the document.

Sub InsertBibliography()
'Apply Header for previous section
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
LinkToPrevious
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="Header 1"
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=vbTab & vbTab & "Date Issue"
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=16
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

Selection.InsertBreak Type:=wdSectionBreakNextPage
'Selection.InsertBreak Type:=wdPageBreak
Selection.TypeText Text:="Bibliography"
Selection.MoveLeft Unit:=wdCharacter, Count:=12, Extend:=wdExtend
Selection.Font.Color = wdColorGreen
Selection.Font.Bold = wdToggle
Selection.Font.Size = 16
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeParagraph
Selection.Font.Size = 12
Selection.Font.Color = wdColorAutomatic

'Apply Header for Bibliography
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
'Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
LinkToPrevious
Selection.TypeText Text:="Company Name"
Selection.MoveLeft Unit:=wdCharacter, Count:=11, Extend:=wdExtend
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="clientname"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=vbTab & vbTab & "Report Line1"
Selection.MoveLeft Unit:=wdCharacter, Count:=12, Extend:=wdExtend
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="reportline1"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeParagraph
Selection.TypeText Text:=vbTab & vbTab & "Report Line2"
Selection.MoveLeft Unit:=wdCharacter, Count:=12, Extend:=wdExtend
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="reportline2"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

'Apply Footer
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.TypeText Text:=vbTab & "Page S"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage

Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
LinkToPrevious

With Selection.HeaderFooter.PageNumbers
.NumberStyle = wdPageNumberStyleArabic
.HeadingLevelForChapter = 0
.IncludeChapterNumber = False
.ChapterPageSeparator = wdSeparatorHyphen
.RestartNumberingAtSection = True
.StartingNumber = 1
End With

Selection.MoveUp Unit:=wdLine, Count:=3
Selection.MoveRight Unit:=wdCharacter, Count:=7
Selection.TypeBackspace

ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

End Sub

Bibliography Section will have its own Page format in the Footer namely Page
S1, Page S2, and so on. Whereas for the content of the doc, Page 1, 2, etc.
is used.

Greatly appreciate if anyone might be able to give me your advise here.

Thank you in advance

Re: unlink Footer/Header in VBA by Shauna

Shauna
Tue Jan 08 03:10:13 PST 2008

Hi Associates

Can you back up here a few steps and tell us:

(a) What are you trying to achieve here? Explain it in words you'd use
to your manager's manager.

(b) How does the user decide to insert the Bibliography? For example, do
you want the user to click on a button on a toolbar, or is this code
part of something larger?

(c) Will users insert a bibliography into all different kinds of
documents, or just some specific kinds of documents?

(d) Where in the document is the bibliography inserted? For example, is
it always at the very end of the document?

Shauna

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



"Associates" <Associates@discussions.microsoft.com> wrote in message
news:72F1BBAE-18C8-4CD1-81C6-7B077DCE0F79@microsoft.com...
> Hi,
>
> I need your help desperately. I've been trying to get this to work
> since
> yesterday but to no avail. I was trying to insert Header/Footer using
> VBA in
> word 03. This will involve section breaks insertion into the document.
>
> My problem is i think i haven't really put the following code in the
> right
> place.
> Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter.
> _
> LinkToPrevious
>
> Different Sections will have different Header and Footer in the
> document.
>
> Here is my code of inserting a section of "Bibliography" into the
> document.
> This might be placed in the middle of the document.
>
> Sub InsertBibliography()
> 'Apply Header for previous section
> If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
> ActiveWindow.Panes(2).Close
> End If
> If ActiveWindow.ActivePane.View.Type = wdNormalView Or
> ActiveWindow. _
> ActivePane.View.Type = wdOutlineView Then
> ActiveWindow.ActivePane.View.Type = wdPrintView
> End If
> ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
> Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter.
> _
> LinkToPrevious
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.TypeText Text:="Header 1"
> Selection.MoveRight Unit:=wdCharacter, Count:=2
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.TypeText Text:=vbTab & vbTab & "Date Issue"
> Selection.MoveDown Unit:=wdLine, Count:=1
> Selection.MoveLeft Unit:=wdCharacter, Count:=16
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.Delete Unit:=wdCharacter, Count:=1
> ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
>
> Selection.InsertBreak Type:=wdSectionBreakNextPage
> 'Selection.InsertBreak Type:=wdPageBreak
> Selection.TypeText Text:="Bibliography"
> Selection.MoveLeft Unit:=wdCharacter, Count:=12, Extend:=wdExtend
> Selection.Font.Color = wdColorGreen
> Selection.Font.Bold = wdToggle
> Selection.Font.Size = 16
> Selection.MoveRight Unit:=wdCharacter, Count:=1
> Selection.TypeParagraph
> Selection.Font.Size = 12
> Selection.Font.Color = wdColorAutomatic
>
> 'Apply Header for Bibliography
> If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
> ActiveWindow.Panes(2).Close
> End If
> If ActiveWindow.ActivePane.View.Type = wdNormalView Or
> ActiveWindow. _
> ActivePane.View.Type = wdOutlineView Then
> ActiveWindow.ActivePane.View.Type = wdPrintView
> End If
> ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
> 'Selection.HeaderFooter.LinkToPrevious = Not
> Selection.HeaderFooter. _
> LinkToPrevious
> Selection.TypeText Text:="Company Name"
> Selection.MoveLeft Unit:=wdCharacter, Count:=11, Extend:=wdExtend
> With ActiveDocument.Bookmarks
> .Add Range:=Selection.Range, Name:="clientname"
> .DefaultSorting = wdSortByName
> .ShowHidden = False
> End With
> Selection.MoveRight Unit:=wdCharacter, Count:=1
> Selection.TypeText Text:=vbTab & vbTab & "Report Line1"
> Selection.MoveLeft Unit:=wdCharacter, Count:=12, Extend:=wdExtend
> With ActiveDocument.Bookmarks
> .Add Range:=Selection.Range, Name:="reportline1"
> .DefaultSorting = wdSortByName
> .ShowHidden = False
> End With
> Selection.MoveRight Unit:=wdCharacter, Count:=1
> Selection.TypeParagraph
> Selection.TypeText Text:=vbTab & vbTab & "Report Line2"
> Selection.MoveLeft Unit:=wdCharacter, Count:=12, Extend:=wdExtend
> With ActiveDocument.Bookmarks
> .Add Range:=Selection.Range, Name:="reportline2"
> .DefaultSorting = wdSortByName
> .ShowHidden = False
> End With
> ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
>
> 'Apply Footer
> If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
> ActiveWindow.Panes(2).Close
> End If
> If ActiveWindow.ActivePane.View.Type = wdNormalView Or
> ActiveWindow. _
> ActivePane.View.Type = wdOutlineView Then
> ActiveWindow.ActivePane.View.Type = wdPrintView
> End If
> ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
> ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
> If Selection.HeaderFooter.IsHeader = True Then
> ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
> Else
> ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
> End If
> Selection.TypeText Text:=vbTab & "Page S"
> Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
>
> Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter.
> _
> LinkToPrevious
>
> With Selection.HeaderFooter.PageNumbers
> .NumberStyle = wdPageNumberStyleArabic
> .HeadingLevelForChapter = 0
> .IncludeChapterNumber = False
> .ChapterPageSeparator = wdSeparatorHyphen
> .RestartNumberingAtSection = True
> .StartingNumber = 1
> End With
>
> Selection.MoveUp Unit:=wdLine, Count:=3
> Selection.MoveRight Unit:=wdCharacter, Count:=7
> Selection.TypeBackspace
>
> ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
>
> End Sub
>
> Bibliography Section will have its own Page format in the Footer
> namely Page
> S1, Page S2, and so on. Whereas for the content of the doc, Page 1, 2,
> etc.
> is used.
>
> Greatly appreciate if anyone might be able to give me your advise
> here.
>
> Thank you in advance
>
>
>
>



Re: unlink Footer/Header in VBA by Associates

Associates
Tue Jan 08 16:33:00 PST 2008

Hi Shauna,

Sorry for not providing you with sufficient info.

(a) What are you trying to achieve here?
The aim here is to set up a standard document template that would enable our
staff to create a report for our company. At the moment, many reports are
different in terms of format. There are lots of inconsistencies throughout
all the reports made by different staff. So we thought, by having a proper
template made ready for staff to use, we could resolve this issue.

In the template (.dot), we plan on making lots of macros placed in the menu
that would enable user to do the job they desire. For example, we have macros
called "insert a section", "insert picture", "insert table", and so on. I
know these would override the features provided by word 03. But these macros
would shorten the steps needed for the staff to say "insert a section or sub
section" for example.

At the moment, i was creating a macro that would insert a bibliography into
the document. By clicking the button "insert bibliography", it would
automatically create a new section break and put the word "bibliography" as
the heading with appropriate header and footer. Of course, this will depend
on the location of the insertion point of the cursor as the bibliography
section will be created in the next page.

So far, I'm struggling to make macro to insert the bibliography section as
well as its footer and header to the document (the code for the macro was
posted earlier). Each of the sections (for example bibliography, glossary,
etc) have their own different format of header and footer. So this involves
lots of "unlink and link to the previous" as far as the header/footer is
concerned.

> (c) Will users insert a bibliography into all different kinds of
> documents, or just some specific kinds of documents?
My idea was everytime someone wants to make up a document report for their
client. He/she can run this template and work on the report.

All the macros are available listed in the customised menu specifically for
our own use.

Hopefully i explained it in words that can make things a lot clearer for you.

I'm happy and open to any other bright ideas you or anyone might like to
share. But this is the actual problem we're facing and trying to resolve it.
And if we can pull this off - it would hopefully reduce time spent on
checking for inconsistencies or errors found.

Thank you in advance

"Shauna Kelly" wrote:

> Hi Associates
>
> Can you back up here a few steps and tell us:
>
> (a) What are you trying to achieve here? Explain it in words you'd use
> to your manager's manager.
>
> (b) How does the user decide to insert the Bibliography? For example, do
> you want the user to click on a button on a toolbar, or is this code
> part of something larger?
>
> (c) Will users insert a bibliography into all different kinds of
> documents, or just some specific kinds of documents?
>
> (d) Where in the document is the bibliography inserted? For example, is
> it always at the very end of the document?
>
> Shauna
>
> Shauna Kelly. Microsoft MVP.
> http://www.shaunakelly.com/word
>
>
>
> "Associates" <Associates@discussions.microsoft.com> wrote in message
> news:72F1BBAE-18C8-4CD1-81C6-7B077DCE0F79@microsoft.com...
> > Hi,
> >
> > I need your help desperately. I've been trying to get this to work
> > since
> > yesterday but to no avail. I was trying to insert Header/Footer using
> > VBA in
> > word 03. This will involve section breaks insertion into the document.
> >
> > My problem is i think i haven't really put the following code in the
> > right
> > place.
> > Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter.
> > _
> > LinkToPrevious
> >
> > Different Sections will have different Header and Footer in the
> > document.
> >
> > Here is my code of inserting a section of "Bibliography" into the
> > document.
> > This might be placed in the middle of the document.
> >
> > Sub InsertBibliography()
> > 'Apply Header for previous section
> > If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
> > ActiveWindow.Panes(2).Close
> > End If
> > If ActiveWindow.ActivePane.View.Type = wdNormalView Or
> > ActiveWindow. _
> > ActivePane.View.Type = wdOutlineView Then
> > ActiveWindow.ActivePane.View.Type = wdPrintView
> > End If
> > ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
> > Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter.
> > _
> > LinkToPrevious
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.TypeText Text:="Header 1"
> > Selection.MoveRight Unit:=wdCharacter, Count:=2
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.TypeText Text:=vbTab & vbTab & "Date Issue"
> > Selection.MoveDown Unit:=wdLine, Count:=1
> > Selection.MoveLeft Unit:=wdCharacter, Count:=16
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > Selection.Delete Unit:=wdCharacter, Count:=1
> > ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
> >
> > Selection.InsertBreak Type:=wdSectionBreakNextPage
> > 'Selection.InsertBreak Type:=wdPageBreak
> > Selection.TypeText Text:="Bibliography"
> > Selection.MoveLeft Unit:=wdCharacter, Count:=12, Extend:=wdExtend
> > Selection.Font.Color = wdColorGreen
> > Selection.Font.Bold = wdToggle
> > Selection.Font.Size = 16
> > Selection.MoveRight Unit:=wdCharacter, Count:=1
> > Selection.TypeParagraph
> > Selection.Font.Size = 12
> > Selection.Font.Color = wdColorAutomatic
> >
> > 'Apply Header for Bibliography
> > If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
> > ActiveWindow.Panes(2).Close
> > End If
> > If ActiveWindow.ActivePane.View.Type = wdNormalView Or
> > ActiveWindow. _
> > ActivePane.View.Type = wdOutlineView Then
> > ActiveWindow.ActivePane.View.Type = wdPrintView
> > End If
> > ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
> > 'Selection.HeaderFooter.LinkToPrevious = Not
> > Selection.HeaderFooter. _
> > LinkToPrevious
> > Selection.TypeText Text:="Company Name"
> > Selection.MoveLeft Unit:=wdCharacter, Count:=11, Extend:=wdExtend
> > With ActiveDocument.Bookmarks
> > .Add Range:=Selection.Range, Name:="clientname"
> > .DefaultSorting = wdSortByName
> > .ShowHidden = False
> > End With
> > Selection.MoveRight Unit:=wdCharacter, Count:=1
> > Selection.TypeText Text:=vbTab & vbTab & "Report Line1"
> > Selection.MoveLeft Unit:=wdCharacter, Count:=12, Extend:=wdExtend
> > With ActiveDocument.Bookmarks
> > .Add Range:=Selection.Range, Name:="reportline1"
> > .DefaultSorting = wdSortByName
> > .ShowHidden = False
> > End With
> > Selection.MoveRight Unit:=wdCharacter, Count:=1
> > Selection.TypeParagraph
> > Selection.TypeText Text:=vbTab & vbTab & "Report Line2"
> > Selection.MoveLeft Unit:=wdCharacter, Count:=12, Extend:=wdExtend
> > With ActiveDocument.Bookmarks
> > .Add Range:=Selection.Range, Name:="reportline2"
> > .DefaultSorting = wdSortByName
> > .ShowHidden = False
> > End With
> > ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
> >
> > 'Apply Footer
> > If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
> > ActiveWindow.Panes(2).Close
> > End If
> > If ActiveWindow.ActivePane.View.Type = wdNormalView Or
> > ActiveWindow. _
> > ActivePane.View.Type = wdOutlineView Then
> > ActiveWindow.ActivePane.View.Type = wdPrintView
> > End If
> > ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
> > ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
> > If Selection.HeaderFooter.IsHeader = True Then
> > ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
> > Else
> > ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
> > End If
> > Selection.TypeText Text:=vbTab & "Page S"
> > Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
> >
> > Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter.
> > _
> > LinkToPrevious
> >
> > With Selection.HeaderFooter.PageNumbers
> > .NumberStyle = wdPageNumberStyleArabic
> > .HeadingLevelForChapter = 0
> > .IncludeChapterNumber = False
> > .ChapterPageSeparator = wdSeparatorHyphen
> > .RestartNumberingAtSection = True
> > .StartingNumber = 1
> > End With
> >
> > Selection.MoveUp Unit:=wdLine, Count:=3
> > Selection.MoveRight Unit:=wdCharacter, Count:=7
> > Selection.TypeBackspace
> >
> > ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
> >
> > End Sub
> >
> > Bibliography Section will have its own Page format in the Footer
> > namely Page
> > S1, Page S2, and so on. Whereas for the content of the doc, Page 1, 2,
> > etc.
> > is used.
> >
> > Greatly appreciate if anyone might be able to give me your advise
> > here.
> >
> > Thank you in advance
> >
> >
> >
> >
>
>
>

Re: unlink Footer/Header in VBA by Shauna

Shauna
Wed Jan 09 02:05:27 PST 2008

Hi "Associates"

Thanks for the explanation. That helps a lot. Here is what I would
suggest:

1. Create a new .dot file. Do that by doing File > New and choosing to
create a template. Use the user interface to create the styles and page
format (eg paper size, margins) that you need in the template.

2. In the template, create an AutoText for each of the things that you
want people to add to the document. From what you say, you'll need an
AutoText for:
- a table
- a bibliography

You probably don't want to include a section break after the table
AutoText, but you can include a section break after the Bibliography
AutoText. The section break will include the headers and footers you
need.

If you want to make an AutoText of a table, select the table using Table
> Select > Table. Just make that the AutoText. Don't include any
extraneous paragraphs before or after it (unless, of course, you
suddenly decide you

More info at: Using AutoText
http://www.word.mvps.org/FAQs/Customization/AutoText.htm


3. Use Tools > Customize and make sure that the "Save in" box refers to
your template.

On the Toolbars tab, create a new toolbar. Keep the Customize dialog
open.

On the Commands tab, in the Categories list, choose Insert. In the
Commands list find the button that says "From file" and has a picture
icon. Drag that to your menu. Right-click this new button on your menu
and change the caption to whatever suits. This one button will now
invoke the Insert > Picture > From File command. You won't need to write
any code to manage getting the image file and path name, coping if the
user presses Esc half way through the process, detecting the kind of
image etc etc.

Back in the Customize dialog, on the Commands tab, in the Categories
list, click New Menu. In the Commands list, you'll see New Menu with an
arrow. Drag that to your new toolbar. Right-click it and give it a new
caption (eg "Insert...").

Now, back in the Customize dialog, on the Commands tab, in the
Categories list, click AutoText. In the Commands list you'll now see the
AutoTexts you created. Drag each of them on to your new menu.




So, you now have a menu with a button that will allow people to insert a
picture, and a menu that will allow people to insert the content you
stored in AutoTexts.

You probably don't need any of the code you currently have. You'll need
to fiddle around with section breaks and the headers/footers but
depending on your needs, you might not need any code at all.


Hope this helps. Write back if you need more details.

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




"Associates" <Associates@discussions.microsoft.com> wrote in message
news:6C3E1512-77CC-4BB7-B371-185B96B6E36C@microsoft.com...
> Hi Shauna,
>
> Sorry for not providing you with sufficient info.
>
> (a) What are you trying to achieve here?
> The aim here is to set up a standard document template that would
> enable our
> staff to create a report for our company. At the moment, many reports
> are
> different in terms of format. There are lots of inconsistencies
> throughout
> all the reports made by different staff. So we thought, by having a
> proper
> template made ready for staff to use, we could resolve this issue.
>
> In the template (.dot), we plan on making lots of macros placed in the
> menu
> that would enable user to do the job they desire. For example, we have
> macros
> called "insert a section", "insert picture", "insert table", and so
> on. I
> know these would override the features provided by word 03. But these
> macros
> would shorten the steps needed for the staff to say "insert a section
> or sub
> section" for example.
>
> At the moment, i was creating a macro that would insert a bibliography
> into
> the document. By clicking the button "insert bibliography", it would
> automatically create a new section break and put the word
> "bibliography" as
> the heading with appropriate header and footer. Of course, this will
> depend
> on the location of the insertion point of the cursor as the
> bibliography
> section will be created in the next page.
>
> So far, I'm struggling to make macro to insert the bibliography
> section as
> well as its footer and header to the document (the code for the macro
> was
> posted earlier). Each of the sections (for example bibliography,
> glossary,
> etc) have their own different format of header and footer. So this
> involves
> lots of "unlink and link to the previous" as far as the header/footer
> is
> concerned.
>
>> (c) Will users insert a bibliography into all different kinds of
>> documents, or just some specific kinds of documents?
> My idea was everytime someone wants to make up a document report for
> their
> client. He/she can run this template and work on the report.
>
> All the macros are available listed in the customised menu
> specifically for
> our own use.
>
> Hopefully i explained it in words that can make things a lot clearer
> for you.
>
> I'm happy and open to any other bright ideas you or anyone might like
> to
> share. But this is the actual problem we're facing and trying to
> resolve it.
> And if we can pull this off - it would hopefully reduce time spent on
> checking for inconsistencies or errors found.
>
> Thank you in advance
>
> "Shauna Kelly" wrote:
>
>> Hi Associates
>>
>> Can you back up here a few steps and tell us:
>>
>> (a) What are you trying to achieve here? Explain it in words you'd
>> use
>> to your manager's manager.
>>
>> (b) How does the user decide to insert the Bibliography? For example,
>> do
>> you want the user to click on a button on a toolbar, or is this code
>> part of something larger?
>>
>> (c) Will users insert a bibliography into all different kinds of
>> documents, or just some specific kinds of documents?
>>
>> (d) Where in the document is the bibliography inserted? For example,
>> is
>> it always at the very end of the document?
>>
>> Shauna
>>
>> Shauna Kelly. Microsoft MVP.
>> http://www.shaunakelly.com/word
>>
>>
>>
>> "Associates" <Associates@discussions.microsoft.com> wrote in message
>> news:72F1BBAE-18C8-4CD1-81C6-7B077DCE0F79@microsoft.com...
>> > Hi,
>> >
>> > I need your help desperately. I've been trying to get this to work
>> > since
>> > yesterday but to no avail. I was trying to insert Header/Footer
>> > using
>> > VBA in
>> > word 03. This will involve section breaks insertion into the
>> > document.
>> >
>> > My problem is i think i haven't really put the following code in
>> > the
>> > right
>> > place.
>> > Selection.HeaderFooter.LinkToPrevious = Not
>> > Selection.HeaderFooter.
>> > _
>> > LinkToPrevious
>> >
>> > Different Sections will have different Header and Footer in the
>> > document.
>> >
>> > Here is my code of inserting a section of "Bibliography" into the
>> > document.
>> > This might be placed in the middle of the document.
>> >
>> > Sub InsertBibliography()
>> > 'Apply Header for previous section
>> > If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
>> > ActiveWindow.Panes(2).Close
>> > End If
>> > If ActiveWindow.ActivePane.View.Type = wdNormalView Or
>> > ActiveWindow. _
>> > ActivePane.View.Type = wdOutlineView Then
>> > ActiveWindow.ActivePane.View.Type = wdPrintView
>> > End If
>> > ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
>> > Selection.HeaderFooter.LinkToPrevious = Not
>> > Selection.HeaderFooter.
>> > _
>> > LinkToPrevious
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.TypeText Text:="Header 1"
>> > Selection.MoveRight Unit:=wdCharacter, Count:=2
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.TypeText Text:=vbTab & vbTab & "Date Issue"
>> > Selection.MoveDown Unit:=wdLine, Count:=1
>> > Selection.MoveLeft Unit:=wdCharacter, Count:=16
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > Selection.Delete Unit:=wdCharacter, Count:=1
>> > ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
>> >
>> > Selection.InsertBreak Type:=wdSectionBreakNextPage
>> > 'Selection.InsertBreak Type:=wdPageBreak
>> > Selection.TypeText Text:="Bibliography"
>> > Selection.MoveLeft Unit:=wdCharacter, Count:=12,
>> > Extend:=wdExtend
>> > Selection.Font.Color = wdColorGreen
>> > Selection.Font.Bold = wdToggle
>> > Selection.Font.Size = 16
>> > Selection.MoveRight Unit:=wdCharacter, Count:=1
>> > Selection.TypeParagraph
>> > Selection.Font.Size = 12
>> > Selection.Font.Color = wdColorAutomatic
>> >
>> > 'Apply Header for Bibliography
>> > If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
>> > ActiveWindow.Panes(2).Close
>> > End If
>> > If ActiveWindow.ActivePane.View.Type = wdNormalView Or
>> > ActiveWindow. _
>> > ActivePane.View.Type = wdOutlineView Then
>> > ActiveWindow.Active