PDA

View Full Version : Check for active Word document



JvL
09-27-2007, 12:00 AM
Dear all,

I want to past a table in an Active word document. Before pasting I want to check if there is a active word document or not. Something like:



If AppActivate("Microsoft Word") = false then
MsgBox Prompt:="U heeft op dit moment geen Word-document geopend"
Exit Sub
End if



Of coarse I got a failure message, can someone help me with the correct code?

Thx

Bob Phillips
09-27-2007, 12:31 AM
Dim AppWord As Object
Dim docWord As Object

On Error Resume Next
Set AppWord = GetObject(, "Word.Application")
If AppWord Is Nothing Then
MsgBox Prompt:="U heeft op dit moment geen Word-document geopend"
Exit Sub
Else
Set docWord = AppWord.activedocument
If docWord Is Nothing Then
MsgBox Prompt:="U heeft op dit moment geen Word-document geopend"
Exit Sub
End If
End If
On Error GoTo 0