Consulting

Results 1 to 2 of 2

Thread: Check for active Word document

  1. #1
    VBAX Regular
    Joined
    Sep 2007
    Posts
    10
    Location

    Check for active Word document

    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:


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


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

    Thx

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •