HOWTO: Print an Embedded Word Document in Visual Basic |
Q112196
Microsoft Word for Windows version 6.0 disables the ability to use the FilePrint and FilePrintDefault methods while an object is being edited in an OLE container. While the menu options may not be enabled, it is still possible to get around this in code. This article explains how.
Commands that are part of the workspace are the responsibility of the top
container (the Visual Basic application). That is, the application is
responsible for the organization of windows, file level operations, and how
edits are ultimately saved. The top container must supply a single File
menu that contains file level commands such as Open, Close, Save, and
Print. If the object is an opened object server application, the commands
in its File menu are modified to show containership (Close & Return to
<container doc>, Exit & Return to <container doc>).
A well-behaved OLE server will not allow workspace commands to be executed.
This is why they are disabled. To work around the problem, edit the object
in the server application instead of using in-place editing. In the server
workspace, commands are enabled. Therefore, you can edit the object in the
server workspace and use OLE Automation to control the server to execute
the Workspace commands.
Sub Command_Click()
' Open application in separate application Window:
ole1.Verb = -2
' Activate Object:
ole1.Action = 7
Dim WB As object
' Alias WordBasic Object:
Set WB = ole1.Object.application.wordbasic
' Disable background printing:
WB.ToolsOptionsPrint , , , , , , , , , , , 0
WB.FilePrintDefault 'Print the Word Object.
' Hint: it may be necessary to check page layout parameters before
' printing. If parameters are outside of the printable region, Word
' will display an error message.
End Sub Additional query words:
Keywords : kbAutomation kbCtrl kbVBp300 kbWord
Issue type : kbhowto
Technology :
|
Last Reviewed: March 7, 2000 © 2001 Microsoft Corporation. All rights reserved. Terms of Use. |