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 / June 2005

Tip: Looking for answers? Try searching our database.

How to unlink headers/footers correctly without using ActiveWindow

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ESH@edbgruppen.dk - 22 Jun 2005 08:19 GMT
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
Jonathan West - 22 Jun 2005 11:28 GMT
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

Signature

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

> Hey
>
[quoted text clipped - 30 lines]
>
> Ebbe
ESH@edbgruppen.dk - 23 Jun 2005 10:06 GMT
Hey

I have decided NOT to run the application invisible.
It involves too many changes :-(

Instead I run the macros minimized.
Doing this, I have one little problem:

When I open a new document with:
   Documents.Open FileName:=BaseDocumentFullName, ReadOnly:=True
   ActiveWindow.WindowState = wdWindowStateMinimize
The document pops up for a secund before it is minimized.

Are there any way I can do a "open minimized" to avoid this short pop-up?

Ebbe
Jonathan West - 23 Jun 2005 10:57 GMT
> Hey
>
[quoted text clipped - 12 lines]
>
> Ebbe

Hi Ebbe

Try this

   Application.Screenupdating = False
   Documents.Open FileName:=BaseDocumentFullName, ReadOnly:=True
   ActiveWindow.WindowState = wdWindowStateMinimize

   Application.Screenupdating = True

Signature

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@edbgruppen.dk - 23 Jun 2005 12:08 GMT
Thank you Jonathan.

It didn't prevent the window to pop up, but it shortened the time it was
visible essentially.

Ebbe
 
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.