AutoOpen and ActiveWindow.View.DisplayPageBoundaries in Microsoft 365 Word

Keith Burgess 1 Reputation point
2022-05-02T23:35:16.25+00:00

I would like all documents I re-open to hide the white space (including headers and footers) between pages. This occurs if I open a document and double-click the white space between pages. It works if I set "ActiveWindow.View.DisplayPageBoundaries = False" in a macro running on an open document and stays that way until I save the document. More to the point, it works (for a few seconds) if I place "ActiveWindow.View.DisplayPageBoundaries = False" into the AutoOpen macro in Normal.dot.

... but immediately after the AutoOpen macro finishes, Word displays the document without the white space, the screen refreshes and is then re-displayed WITH the white space. I can see using the Immediate window that DisplayPageBoundaries becomes True. Is there a way to get DisplayPageBoundaries = False to stick if it's set in the AutoOpen subroutine?

0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Keith Burgess 1 Reputation point
    2023-02-27T08:35:45.29+00:00

    I had the same question.

    Setting "ActiveWindow.View.DisplayPageBoundaries = False" in AutoOpen() works and sticks if you open a document from within Word (when the Word App is already loaded). It works for a few seconds but does NOT stick, as you point out, ... if Word is spawned by the OS when you double-click on a Word Doc and the Word App isn't previously loaded.

    It appears to me that Word resets this attribute after it closes out AutoOpen. Here is an inelegant workaround: schedule another Macro to set this attribute a couple of seconds after AutoOpen closes:

    Sub AutoOpen()
    
        Dim ScheduledTime As Double
        Dim SpawnedSub As String
        
        ScheduledTime = Now + TimeSerial(0, 0, 2)
        SpawnedSub = "TurnOffDisplayPageBoundaries"
        Application.OnTime ScheduledTime, SpawnedSub
            
    End Sub
    
    Public Sub TurnOffDisplayPageBoundaries()
        
       ' Hide white space between pages by default.
        With ActiveWindow.View
            .Type = wdPrintView
            .DisplayPageBoundaries = False
        End With
        Application.ScreenUpdating = True
        
    End Sub
    
    0 comments No comments

  2. Keith Burgess 1 Reputation point
    2023-02-27T08:44:54.4+00:00

    [Note: The tool displaying this question is not working correctly. The question asked above, "I would like all documents I re-open to hide the white space...", was written by somebody else on May 2, 2022. My response below is created on Feb 27, 2023]

    Setting "ActiveWindow.View.DisplayPageBoundaries = False" in AutoOpen() works and sticks if you open a document from within Word (when the Word App is already loaded). It works for a few seconds but does NOT stick, as the above person points out, ... if Word is spawned by the OS when you double-click on a Word Doc and the Word App isn't previously loaded.

    It appears to me that Word resets this attribute after it closes out AutoOpen. Here is an inelegant workaround: schedule another Macro to set this attribute after AutoOpen closes:

    Sub AutoOpen()
    
        Dim ScheduledTime As Double
        Dim SpawnedSub As String
        
        ScheduledTime = Now + TimeSerial(0, 0, 2)
        SpawnedSub = "TurnOffDisplayPageBoundaries"
        Application.OnTime ScheduledTime, SpawnedSub	'This will schedule the task 2 seconds into the future
            
    End Sub
    
    Public Sub TurnOffDisplayPageBoundaries()
        
       ' Hide white space between pages by default.
        With ActiveWindow.View
            .Type = wdPrintView
            .DisplayPageBoundaries = False
        End With
        Application.ScreenUpdating = True
        
    End Sub
    
    0 comments No comments