Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
PrintPreview on MS-Word
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00671045
Message ID:
00727361
Views:
7
I know that this is a relatively old thread, but for the sake of anyone else who may be searching for a solution to this and for whom, for whatever reason, the solution already prescribed here doesn't work, the following code works for me. I assume the difference must be one version of Word vs. another (I'm using 9.0). So the next time someone is searching for how to preview a Word document from VFP and then close Word when the user closes the preview window, maybe one of these methods will work for you too:

* WordPreviewTest.PRG

LOCAL ii AS Integer
LOCAL loDoc AS "Word.Document"

DECLARE integer Sleep in Win32API integer

loDoc = CREATEOBJECT("Word.Document")
loDoc.Application.Visible=.T.
loDoc.Range.InsertAfter("This is a test.")
loDoc.PrintPreview()

#DEFINE wdPrintPreview 4
#DEFINE nLimit 500

* Put up a message just in case they switch back without closing the preview window.
WAIT WINDOW NOWAIT NOCLEAR "Please close the document preview window in Word to continue."

ii = 1
DO WHILE loDoc.Application.ActiveWindow.View.Type = wdPrintPreview AND ii <= nLimit
*Loop until the user closes print preview or the time limit is reached.
Sleep(500)
ii = ii + 1
ENDDO

WAIT CLEAR

loDoc.Application.Visible = .F.
loDoc.Application.Quit( 0 )

MESSAGEBOX( "ii=" + TRANSFORM(ii), 64, "FYI" )


>Hi,
>
>See thread #528482, message #530120. This solved it for me!
>
>HTH
>Kevin
>
>>Hi,
>>
>>When I want a PrintPreview of a MS-Excel worksheet I do this:
>>
>>loExcel = createobject("Excel.Application")
>>loExcel.WorkBooks.Open("Test.Xls")
>>loExcel.Visible = .t.
>>loExcel.ActiveWindow.SelectedSheets.PrintPreview
>>loExcel.Quit
>>
>>Then, after I see the preview, I click on Close buttom, and only after this the Quit line will be processed. It´s all right, here!
>>
>>
>>But with a MS-Word documento I do:
>>
>>loWord = createobject("Word.Application")
>>loWord.Documents.Open("Test.Doc")
>>loWord.Visible = .t.
>>loWord.Documents.ActiveDocument.PrintPreview
>>loWord.Quit
>>
>>Here´s the problem: I can´t view because there isn´t pause between the .PrintPreviw line and the .Quit line.
>>
>>How can I force it to wait?
>>
>>Thanks.
Previous
Reply
Map
View

Click here to load this message in the networking platform