0

I have:

Dim oDoc As OLEObject
Set oDoc = WS.OLEObjects("WordDoc")
oDoc.Activate
...

How can I made oDoc.Deactivate? (So have EndTask the WINWORD.EXE)

Community
  • 1
  • 1
Tuberose
  • 434
  • 6
  • 24
  • The code I gave you in "Is Winword.exe running" contains this - down at the very end where you find the comment: 'Deactivate the document. – Cindy Meister Jan 29 '18 at 14:31
  • @CindyMeister, I commend there. the Cleaning part of you answer not deactivating, as I explained. – Tuberose Jan 30 '18 at 06:55

1 Answers1

0
Sub WorkWithOLEWordDoc( )

    'Declaration
    Dim WS As Worksheet
    Dim oDoc As OLEObject

    'Initializing
    Set Ws = WorkSheets("Sheet1")

    Set oDoc = WS.OLEObjects("WordDoc")
    oDoc.Activate

    'Codes works with the activated OLE Document

    'Deactivating
    Dim DCount as Integer
    DCount = 0
    On Error Resume Next
    DCount = Word.Documents.Count
    If Not Err = 0 Then Word.ActiveDocument.Close Else _
        If DCount > 1 Then Word.ActiveDocument.Close Else Word.Application.Quit

    set oDoc = Nothing

End Sub 'WorkWithWordDoc
Tuberose
  • 434
  • 6
  • 24