Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Supress word warnings/messages 1

Status
Not open for further replies.

GOSCO

Technical User
Sep 26, 2000
134
GB
Hi, im writing a VBS script that prints all files in a folder using the relevant application.

Everything works ok though word docs are causing me a problem. I wanted to supress all warning messages when the file is opened. e.g read only and margin warnings etc.

Can this be done?

Code:
Set objWord = WScript.CreateObject("Word.Application")
objWord.Documents.Open objFile.Path
objWord.ActiveDocument.PrintOut
Wscript.Sleep(1000)
objWord.ActiveDocument.Close
objWord.Quit
 


Hi,

How about
Code:
Application.DisplayAlerts = 0
wdAlertsNone constant values is ZERO.


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I'd try something like this:
Code:
Set objWord = WScript.CreateObject("Word.Application")
With objWord
  .DisplayAlerts = False
  .Documents.Open objFile.Path
  .ActiveDocument.PrintOut False
  .ActiveDocument.Close False
  .Quit
End With

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi thanks can tell me what I need to add in the context of my code?

Ive tried to include but it doesn;t seem to work!

 
My suggestion was a replacement, not an addition.
Did you try it ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi thats great, it seems to work well :)

Im iterating through a list of word docs, is this the most efficient way to do this. ie open word > print doc > close doc > close word.

Code:
Set objWord = WScript.CreateObject("Word.Application")
objWord.DisplayAlerts = False
objWord.Documents.Open objFile.Path
objWord.ActiveDocument.PrintOut False
Wscript.Sleep(1000)
objWord.ActiveDocument.Close False
objWord.Quit
 
I'd use something like this:
Code:
Set objWord = WScript.CreateObject("Word.Application")
With objWord
  .DisplayAlerts = False
  For Each objFile In ...
    .Documents.Open objFile.Path
    .ActiveDocument.PrintOut False
    Wscript.Sleep(1000)
    .ActiveDocument.Close False
  Next
  .Quit
End With

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Ok thats slightly quicker. Thanks for your help.

Is there away to supress the "printing" dialogue box as it flashes for a second whilst it prints each document?

 
Personally I would have thought it much quicker to instantiate Word once up front, and then use that one instance for all files. Also I'd be inclined to use the Print verb rather than code all the rest of the guff as well - but you would still have to suppress the dialogs.

Something like this (untested):

Code:
[blue]Set objWord = WScript.CreateObject("Word.Application")
For each objFile in objFolder.Items
    [green]' If Word File (whatever check you are using now)[/green]
        objFile.InvokeVerbex("Print")
    [green]' End If[/green]
Next objfile
objWord.Quit
Set objWord = Nothing[/blue]



Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
In Excel if you set DisplayAlerts = False, it is a permanent setting to the Help options of the office assistant. That is, it doesn't get set to "True" when the procedure ends (like ScreenUpdating does).

I'm not a Word guy but it looks to be the same in Word with the added fact that there are three possible values.

If you are going to have other people using the procedure on their own machines you might want to get the value first, then disable alerts, then reset alerts (at the end of the procedure) back to the user's original setting.
OldAlertValue = ObjWord.DisplayAlerts
OBjWord.DisplayAlerts = 0'
'other code
ObjWord.DisplayAlerts = OldAlertValue

Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top