Word COM on Close event capture Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Stavencross
Posts: 90
Joined: 24 May 2016, 16:42

Word COM on Close event capture

26 Mar 2019, 07:09

I'm trying to pop up a message box when the word app is closed, but I can't seem to figure out what the event is named. If possible, I'd also like to figure out how to pop up a message box when the doc has been saved.

Code: Select all

wdApp := ComObjCreate("Word.Application") ;create a word app
wdApp.Visible := true
oConnect := ComObjConnect(wdApp,"wd_") ;connect to events
wdApp.Documents.Add() ;add a new document


wd_NewDocument(Doc,App) { ;when creating a new document, this triggers
    MsgBox, % Doc.Name                          ; Show the name of the new document
    App.Selection.TypeText("Hello world")       ; Type text at the current selection
}

wd_Close(Doc,App) ;<------------  Here is the problem, I've tried wd_Close,wd_Quit and wd_Exit with no success
    MsgBox, % App.Name ; Show the name of the application
    ComObjConnect(App) ; Disconnect from App events
}
Klarion
Posts: 176
Joined: 26 Mar 2019, 10:02

Re: Word COM on Close event capture

26 Mar 2019, 10:09

Code: Select all

wd_Quit() 
{ 
	MsgBox, % "Yes it's done"    
}
Stavencross
Posts: 90
Joined: 24 May 2016, 16:42

Re: Word COM on Close event capture  Topic is solved

26 Mar 2019, 11:27

I was able to take part of the replies to make the following:

Code: Select all

#Persistent
wdApp := ComObjCreate("Word.Application") ;create a word app
wdApp.Visible := true
oConnect := ComObjConnect(wdApp,"wd_") ;connect to events
wdApp.Documents.Add() ;add a new document


wd_NewDocument(Doc,App) { ;when creating a new document, this triggers
    MsgBox, % Doc.Name                          ; Show the name of the new document
    App.Selection.TypeText("Hello world")       ; Type text at the current selection
}

wd_Quit(App) 
{ 
	MsgBox, % "Yes it's done"    
}
Klarion
Posts: 176
Joined: 26 Mar 2019, 10:02

Re: Word COM on Close event capture

26 Mar 2019, 13:09

1. beg a question
2. get an answer code from someone else
3. check its own comment as an answer
4. conveniently not using the basic word 'thanks'

Brilliant !!!
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Word COM on Close event capture

26 Mar 2019, 14:51

I thought it was a good contribution. Thanks Klarion!

I can tell you that not every response I've experienced or witnessed was fair. Sometimes you even get too much credit, someone marks yours as the answer, when you preferred the other one. And sometimes no response is better than a bad response. But on average responses are pretty good.

I'd respond to you here, but I don't want to receive notifications from that thread. Cheers.
Issues with registering, Post your username here... - Page 33 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=2&t=5008&p=269624#p269624
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Stavencross
Posts: 90
Joined: 24 May 2016, 16:42

Re: Word COM on Close event capture

27 Mar 2019, 08:18

Klarion wrote:
26 Mar 2019, 13:09
1. beg a question
2. get an answer code from someone else
3. check its own comment as an answer
4. conveniently not using the basic word 'thanks'

Brilliant !!!
Apologies, I had written a response with a thank you in it and forgot to click submit on my way to a meeting.

Thank you very much for your assistance, there were a couple things I had to add to your code to make it work correctly, including the #Persistent tag, hence why I posted mine and chose it as the answer. I appreciate your assistance though. Thank you again!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 351 guests