Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Can vbscript capture Word.Application events ?

Reply
 
Old 05-31-2009   #1 (permalink)
hls


 
 

Can vbscript capture Word.Application events ?

I am able to structure a working class vbs file, but I can not find how to
Dim or Set the word object withevents and how to capture the events ?

Thanks for any assistance.


My System SpecsSystem Spec
Old 06-01-2009   #2 (permalink)
Reventlov


 
 

Re: Can vbscript capture Word.Application events ?

Il giorno Sun, 31 May 2009 17:24:34 -0400, "hls" <hml9083@xxxxxx> ha scritto:
Quote:

>I am able to structure a working class vbs file, but I can not find how to
>Dim or Set the word object withevents and how to capture the events ?
dotn't know if it works with word, but try
set objWord=createobject("word.application", "WordEvent_")

and then, if an "onload" event exists and occurs, this sub will be called.

sub WordEvent_OnLoad
....
end sub


--
Giovanni Cenati (Bergamo, Italy)
Write to "Reventlov" at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--
My System SpecsSystem Spec
Old 06-01-2009   #3 (permalink)
mr_unreliable


 
 

Re: Can vbscript capture Word.Application events ?

hls wrote:
Quote:

> I am able to structure a working class vbs file, but I can not find how
> to Dim or Set the word object withevents and how to capture the events ?
>
> Thanks for any assistance.
hi his,

There are (at least) two answers here, assuming that you
are just using WD from vbs, and not wsf or IE.

For events related to the word.application object itself, you may
instantiate the object using wscript's createobject method.

If you want to catch events for this, then use the last parameter
of create object. That will be the prefix of any event handlers
you write. For example:

oWD = WScript.CreateObject("Word.Application", "oWD_")

Then an event handler would look like this...

Sub oWD_Quit()
' add code here...
End Sub

But that's not all. With WD you can generate sub-objects.
I'm not too familiar with scripting word, but with XL an
example of a sub-object might be a worksheet. I "think"
that a comparable sub-object with WD might ba a document.
If you create a new document with word (or any other subobject)
you won't be using the createobject method, just a "Set"
statement.

Set oNewDoc = oWD.Documents.Open(blah, blah, blah... )

In this case you would use the "ConnectObject" method.
For example:

WScript.ConnectObject oNewDoc, "oNewDoc_"

and then write your doc event handlers with the oNewDoc
prefix.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)
My System SpecsSystem Spec
Old 06-02-2009   #4 (permalink)
Harold Little


 
 

Re: Can vbscript capture Word.Application events ?

Thanks so much, I will try both examples.

"hls" <hml9083@xxxxxx> wrote in message
news:3815C117-4685-4555-950E-33A203E036F3@xxxxxx
Quote:

>I am able to structure a working class vbs file, but I can not find how to
>Dim or Set the word object withevents and how to capture the events ?
>
> Thanks for any assistance.

My System SpecsSystem Spec
Old 06-05-2009   #5 (permalink)
Harold Little


 
 

Re: Can vbscript capture Word.Application events ?

I am unable to catch the Word application event "oWD_DocumentBeforePrint"
Any Help would be appreciated.
Thanks
'
'
sTo = "James Wilson" & vbcrlf & "90 Sun Terr." & vbcrlf & "Wilmington, DE
19952"
Dim oWD, oNewDoc
'
Set Env = New Envelope
Env.Preview

Do while Env.PreviewDisplayed()
Wscript.Sleep 200
Loop

Env.DoQuit
Set Env = Nothing
'
'////////////////////////////////////////////////
Class Envelope
Private sub Class_Initialize
Set oWD = WScript.CreateObject("Word.Application", "oWD_")
Set oNewDoc = oWD.Documents.Add
WScript.ConnectObject oNewDoc, "oWD_"
End Sub

Sub Preview()
If not oNewDoc is nothing Then
With oNewDoc
.Envelope.Insert ,sTo
.PrintPreview
.Application.Visible = True
.Application.Activate
End With
End If
End Sub

Private Sub oWD_DocumentBeforePrint(oNewDoc, Cancel)
Msgbox "oWD_DocumentBeforePrint"
End Sub

Function PreviewDisplayed()
PreviewDisplayed = oWd.PrintPreview
End Function

Sub DoQuit()
oWD.Quit 0
End Sub


Private sub Class_Terminate
'
End Sub
End Class

"hls" <hml9083@xxxxxx> wrote in message
news:3815C117-4685-4555-950E-33A203E036F3@xxxxxx
Quote:

>I am able to structure a working class vbs file, but I can not find how to
>Dim or Set the word object withevents and how to capture the events ?
>
> Thanks for any assistance.

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Access textbox contents to Word via VBScript VB Script
[MS Word Macro] VBscript flag image to not print it VB Script
reference / manage application windows with vbscript VB Script
Handling Events in a VBScript Class VB Script
Capture com events PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46