Word Application Object

Hello,

I am trying to preview a Word document from a VB6 application.  I have added a reference to the Microsoft Word 9.0 Object Library, and created a sub called PreviewReport.  I am using Word 2000 running on a WindowsXP machine.  I am also doing the application development on WindowsXP.

The code runs without errors, and I can see Word load and unload in the Windows Task Manager as the sub executes.  However, the PrintPreview command simple does nothing.  When I step through the code, it passes right over it as if it is executing, but the document does not display.

Can anyone tell me what I am doing wrong?

The following code is what I have for my sub...

Private Sub PreviewReport

    Dim wrdApp As Word.Application
    Dim wrdDoc As Word.Document
    Dim wrdSel As Word.Selection

    Set wrdApp = New Word.Application
    Set wrdDoc = wrdApp.Documents.Add
    Set wrdSel = wrdApp.Selection

    wrdApp.Documents.Open ("D:\Test.doc")
    wrdDoc.PrintPreview

    Set wrdSel = Nothing
    Set wrdDoc = Nothing
    wrdApp.Visible = True
    wrdApp.Quit
    Set ardApp = nothing

End Sub

Thanks!
Dave
DaliHowAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JohnMcCannCommented:
Try moving this line further uyp.

wrdApp.Visible = True
   
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TimCotteeHead of Software ServicesCommented:
Hi DaliHow,

You don't set wrdApp.Visible=True until after all the processing has happened. You need to set the object visible at the beginning. I would also suggest that you only close and set the object to nothing in another call as VB will continue to process the commands which will do this so you will still not see much of the preview.

Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk 

Brainbench MVP for Visual Basic
http://www.brainbench.com

Experts-Exchange Advisory Board Member
0
JohnMcCannCommented:
Private Sub PreviewReport

   Dim wrdApp As Word.Application
   Dim wrdDoc As Word.Document
   Dim wrdSel As Word.Selection

   Set wrdApp = New Word.Application
   Set wrdDoc = wrdApp.Documents.Add
   Set wrdSel = wrdApp.Selection

   wrdApp.Documents.Open ("D:\Test.doc")
   wrdDoc.PrintPreview
   wrdApp.Visible = True

   Set wrdSel = Nothing
   Set wrdDoc = Nothing
   wrdApp.Quit
   Set ardApp = nothing

End Sub
0
MarcelStaasCommented:
Dear DaliHow,

I have tried the following code with Word 8.0.

   Dim wrdApp As Word.Application
   Dim wrdDoc As Word.Document

   Set wrdApp = New Word.Application

   wrdApp.Visible = True
   Set wrdDoc = wrdApp.Documents.Open("d:\test.doc")
   wrdDoc.PrintPreview

   'Preview is available
   'as long as next statements are NOT executed
   'because word will be closed
   'Tested with Word 8.0

   Set wrdDoc = Nothing
   wrdApp.Quit
   Set wrdApp = Nothing


Hope this helps.
0
TimCotteeHead of Software ServicesCommented:
Hi, %%QUESTIONER%%

Indeed Marcel, this is as I said earlier, VB will continue to execute those statements so the preview cannot be seen properly. The only way to display a preview using this method is to close the word instance from a seperate function.

Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk 

Brainbench MVP for Visual Basic
http://www.brainbench.com

Experts-Exchange Advisory Board Member
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.