![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 ? 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 Specs![]() |
| | #3 (permalink) |
| | 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. 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||