Article ID: 170393
Article Last Modified on 7/1/2004
oWord = CREATEOBJECT('Word.Basic')
WITH oWord
cWordVersion = oWord.AppInfo(2) &&Get Word version
.FileNew
oValue = .CurValues.ToolsOptionsPrint &&Get background setting
.AppShow
nsetting = oValue.background
IF oValue.background = 1
.ToolsOptionsPrint(,,,,,,,,,,,0)
ENDIF
.Insert ("This is a test.")
.ToolsOptionsPrint(,,,,,,,,,,,0,,,"")
.FilePrintDefault
IF nsetting = 1 &&Reset Background printing
.ToolsOptionsPrint(,,,,,,,,,,,1)
ELSE
.ToolsOptionsPrint(,,,,,,,,,,,0)
ENDIF
IF VAL(cWordVersion) < 8 &&If version=7, then it's Word 95
.FileClose(2) &&Close without prompt to save
oWord = "" &&Release Word object
ELSE &&Else, it's Word 97
.FileClose(2)
.FileQuit
ENDIF
ENDWITH
Using the Word.Application object for Word 97:
oWord = CREATEOBJECT('Word.Application')
WITH oWord
cWordVersion = oWord.Version &&Get Word version
.Documents.Add
.Visible = .T.
.Selection.InsertAfter ("This is a test.")
lBackground = .Options.PrintBackground()
IF lBackground
.Options.PrintBackground = .F.
ENDIF
.Wordbasic.FilePrintDefault
IF lBackground
.Options.Printbackground = !.Options.Printbackground
ENDIF
.Application.Quit(0) &&Quit, don't save & don't prompt
ENDWITH
oWord = CREATEOBJECT('Word.Basic')
WITH oWord
cWordVersion = oWord.AppInfo(2) &&Get Word version
.FileNew
.AppShow
.Insert ("This is a test.")
.FilePrint(0) &&"0" = background printing
IF VAL(cWordVersion) < 8 &&If version=7, then it's Word 95
.FileClose(2) &&Close without prompt to save
oWord = "" &&Release Word object
ELSE &&Else, it's Word 97
.FileClose(2)
.FileQuit
ENDIF
ENDWITH
Using the Word.Application object for Word 97:
oWord = CREATEOBJECT('Word.Application')
WITH oWord
cWordVersion = oWord.Version &&Get Word version
.Documents.Add
.Visible = .T.
.Selection.InsertAfter ("This is a test.")
.Wordbasic.FilePrint(0)
.Application.Quit(0) &&Quit, don't save & don't prompt
ENDWITH
oWord = CREATEOBJECT('Word.Basic')
WITH oWord
cWordVersion = oWord.AppInfo(2) &&Get Word version
.FileNew
.AppShow
.Insert ("This is a test.")
.ToolsMacro("turnoffbackground",1) && Run Word macro
IF VAL(cWordVersion) < 8 &&If version=7, then it's Word 95
.FileClose(2) &&Close without prompt to save
oWord = "" &&Release Word object
ELSE &&Else, it's Word 97
.FileClose(2)
.Filequit
ENDIF
ENDWITH
Visual FoxPro code using the Word.Application object for Word 97:
oWord = CREATEOBJECT('Word.Application')
WITH oWord
.Documents.Add
.Visible = .T.
.Selection.InsertAfter ("This is a test.")
.Run("turnoffbackground") && Run Word macro
.Application.Quit(0) &&Quit, don't save & don't prompt
ENDWITH
Word macro code for use in Method 3:
Sub MAIN
REM Macro to toggle background printing and reset to original value
REM Get current value for Background printing from ToolsOptions
Dim dlg As ToolsOptionsPrint
GetCurValues dlg
cursetting = dlg.Background
If dlg.Background = 1 Then
dlg.Background = 0
End If
ToolsOptionsPrint dlg
REM Reset Background option to original value
If cursetting = 1 Then
dlg.Background = 1
Else
dlg.Background = 0
End If
ToolsOptionsPrint dlg
End Sub
For Word 97, create the following macro. This sample macro is named
turnoffbackground.
Sub turnoffbackground()
REM Macro to toggle off background printing and turn back on if set on.
REM Get current settings
cursetting = Options.PrintBackground
If cursetting = "True" Then
Options.PrintBackground = False
End If
ActiveDocument.PrintOut
If cursetting = "True" Then
Options.PrintBackground = True
End If
End Sub
Keywords: kberrmsg kbhowto kbinterop kbcode KB170393