difficult condition

  • Thread starter Thread starter Phil M
  • Start date Start date
P

Phil M

I'd like to make a macro action conditional on whether a
Microsoft Word document is open or not. Can anyone kindly
tell me what expression to use in the condition column?

(The document is a MailMerge document.)
 
Phil,

As far as I know, this is not possible.

- Steve Schapel, Microsoft Access MVP
 
Perhaps using a function that checks for the Word document being open in the
condition statement would work.

Put this function (not fully tested) in a regular module:

Public Function IsWordDocOpen(strDocumentFileName As String) As Boolean
Dim objWord As Object
Dim intWord As Integer
On Error Resume Next
Set objWord = GetObject("Word.Application")
If Err.Number <> 0 Then
' Word is not open and running, so no Word docs are open
IsWordDocOpen = False
Exit Function
Else
For intWord = 0 To objWord.Documents.Count - 1
If objWord.Documents(intWord).Name = strDocumentFileName Then
IsWordDocOpen = True
Exit Function
End If
Next intWord
IsWordDocOpen = False
End If
End Function

Then use a condition such as this in the macro's Condition:
IsWordDocOpen("NameOfWordDocument") = True

If true, the document is open.
 
Back
Top