Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

give a print preview of the word document

Posted on 1999-01-13
2
Medium Priority
?
201 Views
Last Modified: 2012-05-04
What do i have to do to give a print preview of an existing word document. i´m working with vb5.0 and using word97.

0
Comment
Question by:nimicheck
  • 2
2 Comments
 
LVL 10

Accepted Solution

by:
caraf_g earned 150 total points
ID: 1455969
'Somewhere in a normal VB Module
'For Word interaction
Global g_objWord As Object
---------------------------------------------------

'Wherever you wish to call word
'If Word is not already instantiated, instantiate it now.
If g_objWord Is Nothing Then
    Set g_objWord = CreateObject("Word.Basic")
End If

'Word might have been closed since previous run, catch this error
On Local Error GoTo Err_ExpectedWordErrors:
g_objWord.FileOpen "C:\MyWordFile.Doc"

On Local Error GoTo <Your normal Error Handler>
g_objWord.AppMaximize 1

'Some code here to avoid continuing on into error handlers,
'for example:
Exit Sub

Err_ExpectedWordErrors:
If (Err.Number = 78) Or (Err.Number = 55) Then
    'File not found
    'For example: Exit Sub
End If
If (Err.Number = 70) Then
    'permission denied
    'For example: Exit Sub
End If
'Word may be closed by the user, try to re-instantiate it.
'If anything goes wrong from now on, treat it as any other unexpected error.
On Local Error GoTo <Your normal Error Handler>
Set g_objWord = Nothing
Set g_objWord = CreateObject("Word.Basic")
Resume

<Your normal Error Handler>
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1455970
Note:
The above code will actually open the document, but the good thing is that the user will get the Word interface they are used to and happy with, plus the print option is there for them to choose as usual (Inclusive Print Preview).

Maybe there is an option in Word.Basic to open a document as read only if you wish to do so. Lots of help available when you open Word itself.

Good luck!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

877 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