?
Solved

Word Application Object

Posted on 2003-03-12
5
Medium Priority
?
298 Views
Last Modified: 2010-04-07
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
0
Comment
Question by:DaliHow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
JohnMcCann earned 1000 total points
ID: 8119757
Try moving this line further uyp.

wrdApp.Visible = True
   
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 8119762
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
 
LVL 5

Expert Comment

by:JohnMcCann
ID: 8119767
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
 

Expert Comment

by:MarcelStaas
ID: 8120436
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
 
LVL 43

Expert Comment

by:TimCottee
ID: 8120478
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month9 days, 18 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question