Re: How to unlink headers/footers correctly without using ActiveWindow
- From: "Jonathan West" <jwest@xxxxxxxx>
- Date: Wed, 22 Jun 2005 11:28:47 +0100
I would recommend that if you want the macro to run correctly when invisible, you avoid as far as possible the use of the following objects
- ActiveDocument - Selection - any Window object, including ActiveWindow
For the most part, you can avoid using the ActiveDocument, as follows. When opening a document, using the following syntax
Dim oDoc As Document Set oDoc = Documents.Open(FileName:=C:\test.doc")
After that, whenever you are in the habit of using ActiveDocument, you can use oDoc instead.
Once you have a reference to oDoc, you can do the following to define a range
Dim oRange as Range Set oRange = oDoc.Range(0, 0)
Then you can do almost anything with oRange that you can do with Selection. In addition, you can define as many Range objects as you want or need, and use them all simultaneously. You can only have one Selection.
With regard to breaking the link between sections for the header and footer, you don't need to use the Window objects or the Selection at all for this. There are several ways to approach this but probably the simplest is as follows. Assume that oRange is pointing to somewhere within the section whose header and footer you want to unlink, proceed as follows
With oRange.Sections(1) .Headers(wdHeaderFooterPrimary).LinkToPrevious = False .Footers(wdHeaderFooterPrimary).LinkToPrevious = False End With
-- Regards Jonathan West - Word MVP www.intelligentdocuments.co.uk Please reply to the newsgroup Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
<ESH@xxxxxxxxxxxxx> wrote in message news:%235n45qvdFHA.1384@xxxxxxxxxxxxxxxxxxxxxxx
Hey
As a start I ran a macro with application visible. From the macro recorder I learned to use the following statement to unlink header/footer:
Selection.InsertBreak Type:=wdSectionBreakNextPage
' Cut link between herder/footer on page x and page x+1 ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader Selection.HeaderFooter.LinkToPrevious = False ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
BUT it didn't work when I changed to run the application invisible :-(
In an earlier Q in this NG I was told that the ActiveWindow object only worked correctly when application was visible. I have tried to rewrite the script to the following:
Selection.InsertBreak Type:=wdSectionBreakNextPage
' Cut link between herder/footer on page x and page x+1 With ActiveDocument.Sections(ActiveDocument.Sections.Count) .Headers(wdHeaderFooterPrimary).LinkToPrevious = False .Footers(wdHeaderFooterPrimary).LinkToPrevious = False End With
As far as I can see it does not work. When I manually enters the header on the new page (doubleclicking on the new header), it is STILL linked to previous page.
What am I doing wrong?
Ebbe
.
- Follow-Ups:
- References:
- Prev by Date: Find text with different font.
- Next by Date: Macros & hyperlinks & buttons does not work into headers ??? please help
- Previous by thread: How to unlink headers/footers correctly without using ActiveWindow
- Next by thread: Re: How to unlink headers/footers correctly without using ActiveWindow
- Index(es):