Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I? : Manipulate word window when opening from VBA

Status
Not open for further replies.

thefarg

Programmer
Jan 25, 2012
94
NZ
I am using Word to preview documents from Access 2007. My existing code ....
Code:
'Previews word document(s) from named path
Public Sub PreviewWordDoc(WordDocFullPath As String, Optional Orientation As String = "Portrait")

    Dim objWord As Word.Application
    Set objWord = New Word.Application
    
        With objWord
        
        .Documents.Open filename:=WordDocFullPath, readOnly:=True
            If Orientation = "Landscape" Then _ 
        .ActiveDocument.PageSetup.Orientation = wdOrientLandscape
        .ActiveDocument.ActiveWindow.View.zoom.Percentage = 50
        .CommandBars.item("Ribbon").Enabled = False
        .CommandBars.item("Ribbon").Visible = False
        .windowState = wdWindowStateNormal
        .Visible = True
        End With
End Sub
This opens the document at 50% zoom just to preview. However the word window covers part of the document. Is there a simple way to make the word window fit the documents current display size? I have attempted the minimise the ribbon as well, but disabling, making invisable dont appear to work.
Any ideas?

Cheers
Mike
 
is the window maximized?

.windowState = wdWindowStateMaximize

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work" <<Edison>>
 
No. I prefer to have it as a popup, its a replacement for print preview as I cant get word to print preview without the underlying application window. I could size it with .width and .height but hoped there was a "size to document" type of method/property. Any ideas? This still doesnt help with the ribbon either, which, for a print preview is wasted real estate.
 
try

Code:
.ActiveDocument.ActiveWindow.Panes(1).Zooms(wdPrintView).PageFit = wdPageFitFullPage

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work" <<Edison>>
 
Works great, thanks MazeWorX.
Code:
[COLOR=green]'Word Document handling
'Previews word document(s) from named path[/color]
Public Sub PreviewWordDoc(WordDocFullPath As String, Optional Orientation As String = "Portrait")
    Dim objWord As Word.Application
    Set objWord = New Word.Application
    
        With objWord
            .Documents.Open filename:=WordDocFullPath, readOnly:=True
                If Orientation = "Landscape" Then .ActiveDocument.PageSetup.Orientation = wdOrientLandscape
[COLOR=green]            '.PageSetup.Orientation = wdOrientPortrait[/color]
            .ActiveDocument.ActiveWindow.View.zoom.Percentage = 50
[COLOR=#ff0000]            .ActiveDocument.ActiveWindow.Panes(1).Zooms(wdPrintView).PageFit = wdPageFitFullPage [/color]
[COLOR=green]				'.CommandBars.item("Ribbon").Visible = False [/color]
            .windowState = wdWindowStateNormal
            .Visible = True
        End With
End Sub
My current Sub. Now all I need is to hide or minimise the ribbon. Any ideas?
 
try

Code:
'Word Document handling
'Previews word document(s) from named path
Public Sub PreviewWordDoc(WordDocFullPath As String, Optional Orientation As String = "Portrait")
    Dim objWord As Word.Application
    Set objWord = New Word.Application
    
        With objWord
            .Documents.Open filename:=WordDocFullPath, readOnly:=True
                If Orientation = "Landscape" Then .ActiveDocument.PageSetup.Orientation = wdOrientLandscape
            '.PageSetup.Orientation = wdOrientPortrait
            .ActiveDocument.ActiveWindow.View.zoom.Percentage = 50
            .ActiveDocument.ActiveWindow.Panes(1).Zooms(wdPrintView).PageFit = wdPageFitFullPage
            '.CommandBars.Item("Ribbon").Visible = False
            [red].DoCmd.ShowToolbar "Ribbon", acToolbarNo[/red]
            .windowState = wdWindowStateNormal
            .Visible = True
        End With
End Sub

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work" <<Edison>>
 
method or data member not found." I tried that but DoCmd is only i Access, here I'm manipulating a word object.
 
PHV answered in another thread....
Code:
.ActiveWindow.ToggleRibbon

works perfectly, minimises the ribbon.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top