Kbase 21900: ActiveX -- Workaround For WordBasic FilePrintSetup Method
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  19/03/2002 |
|
SUMMARY:
This Solution shows you how to work around a problem that can occur when calling the WordBasic FilePrintSetup Method from Progress.
The FilePrintSetup Method selects a new printer without having MS Word change the default system printer. However it needs named argument in order to work properly otherwise the printer's dialog-box appears instead. Since Progress does not support named method parameters, it cannot be used directly from Progress.
SOLUTION:
Create a DLL that modifies the MS Word default printer and call it from Progress.
Here is a sample of an ActiveX DLL created from Visual Basic:
1) Create a new ActiveX DLL Visual Basic project
(Called "MyWordBasic" in this sample)
2) Insert the following code in the Class file (class1.cls):
Public Sub SetPrinter( _
oWord As Object, _
ByVal sPrinter As String, _
ByVal bSysDefault As Boolean)
' oWord: Handle of the Word session
' sPrinter: Name of the new printer
' bSysDefault: Specify if the system default printer _
is changed or not
oWord.WordBasic.FilePrintSetup printer:=sPrinter, _
DoNotSetAsSysDefault:=bSysDefault
End Sub
3) Save the project and generate the DLL file (MyWordBasic.dll)
4) From Progress run the code below:
DEFINE VARIABLE chWord AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chWordBasic AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE cPrinter AS CHARACTER NO-UNDO.
cPrinter = "HP LaserJet 4 on LPT2".
CREATE "Word.Application" chWord.
chWord:VISIBLE = true.
chWord:Documents:Add().
/* Set the default printer */
CREATE "MyWordBasic.Class1" chWordBasic.
chWordBasic:SetPrinter(OUTPUT chWord,cPrinter,TRUE).
RELEASE OBJECT chWordBasic.
References to Written Documentation:
Microsoft's Knowledge Base Q216026