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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I detect if a word document is open 1

Status
Not open for further replies.

dongal

Technical User
Feb 18, 2002
10
0
0
GB
Hi all,

I have written the following code to open up a word document and then save it with a time stamp. This works fine. ( Path and File are variants storing the Path and file name of the document)

Set wrd = CreateObject("Word.Application")
Set docBomb = wrd.Documents.Open(Path & File & ".DOC")

wrd.Visible = True

'Get Date and Time for File Name
currentDateTime = Now
TimeStamp = Format(currentDateTime, "dd-mm-yyyy h-nn-ss")
docBomb.SaveAs (Path & File & TimeStamp & ".DOC")

What I want to do now is continue saving this document every 10 seconds until the user closes the document.
Does anybody know how to test to see if the word document is open or closed? Then I can write a Do Until loop, until the user closes the document.

Regards

Dongal
 
you could declare your wrd object as

dim withevents wrd as object

that way you can catch if word is closing and end your loop....

alternatively you can:-

Private Function IsWordAppOpen() As Boolean

On Error Resume Next

'Try first to use an existing instance.
Set myExcelApplication = GetObject(, "Word.Application")

If Err = 429 Then
'Word isn't running
IsWordAppOpen = False
Err.Clear
Else
'Word is running
Set myWordApplication = Nothing
IsWordAppOpen = True
End If

good luck


If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
 
Many thanks for the information, I shall trundle away to my little pit and put it to good use.

Dongal
 
Hi Adoozer,

The second solution to my problem has worked great, many thanks.

Just a question about the first solution, the line Dim withevents wrd as object is not accepted on my system. Also Object is not in the drop down list when I enter the line. Any comments?

Regards

Dongal
 
sorry... my mistake, you would need a reference to the object library for that to work...

my brain obviously wasnt in gear when i wrote that!! [pc]

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top