我有:
Dim oDoc As OLEObject
Set oDoc = WS.OLEObjects("WordDoc")
oDoc.Activate
...
我如何制作oDoc.Deactivate
? (所以EndTask是WINWORD.EXE)
答案 0 :(得分: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