Closing word file when done

Get help with using AutoHotkey and its commands and hotkeys
AHKStudent
Posts: 1021
Joined: 05 May 2018, 12:23

Closing word file when done

06 Oct 2019, 08:55

Code: Select all

oWord := ComObjCreate("Word.Application")
oWord.Visible := False
oWord.Documents.Open(Path)
When im done working with the file I would like to close it so when I open it it does not tell me the file is in use by another user

What is the code? I tried oWord.Documents.Close(Path) and .quit but it did not work
User avatar
Sir Teddy the First
Posts: 94
Joined: 05 Aug 2019, 12:31
Contact:

Re: Closing word file when done

06 Oct 2019, 10:38

Hi,
as .quit() is a function it needs parentheses. This should work:

Code: Select all

oWord := ComObjCreate("Word.Application")
oWord.Visible := False
oWord.Documents.Open(Path)

; .... other Code

oWord.quit()
:eh: :think:
AHKStudent
Posts: 1021
Joined: 05 May 2018, 12:23

Re: Closing word file when done

06 Oct 2019, 11:59

Sir Teddy the First wrote:
06 Oct 2019, 10:38
Hi,
as .quit() is a function it needs parentheses. This should work:

Code: Select all

oWord := ComObjCreate("Word.Application")
oWord.Visible := False
oWord.Documents.Open(Path)

; .... other Code

oWord.quit()
Thank you SIR

When I try that after I run it and go to open the file in word it still shows the file being used by other user
User avatar
flyingDman
Posts: 881
Joined: 29 Sep 2013, 19:01

Re: Closing word file when done

06 Oct 2019, 12:15

You have to close all previous instances using task manager.
To properly close the document, exit word and empty all references use this sequence:

Code: Select all

path := "C:\Users\xxx\test.docx"
oWord := ComObjCreate("Word.Application")               ; create MS Word object
oFile := oWord.Documents.Open(path)               		; create new document
;....
oFile.Close                                             ; close the file
oFile := ""                                             ; release the reference
oWord.Quit()                                            ; close the application
oWord := ""                                             ; release the reference
User avatar
flyingDman
Posts: 881
Joined: 29 Sep 2013, 19:01

Re: Closing word file when done

06 Oct 2019, 12:42

oWord.Quit() and oWord.Quit seem to be identical and I believe oFile.Close is identical to oFile.Close(0) which is close w/o saving (while oFile.Close(-1) is close and save)

Return to “Ask For Help”

Who is online

Users browsing this forum: famko, Sharon, teadrinker and 36 guests