taurean
Well-known Member
- Joined
- Jun 17, 2011
- Messages
- 2,190
- Office Version
- 365
- 2016
- Platform
- Windows
I've searched for this and could not find relevant thread for the task object. Following bit of code runs fine if placed in Word VBA:
I could not find good equivalent of this in Excel. If I've missed it (which is possible) then please tell me, I'd be happy to use it. So I referenced 'Microsoft Word 12.0 Object Library' in Excel and ran the code and it gave me this error 429. Noticeable part was, no instance of word was running at that time.
So I modified the code as below:
And it worked.
Now my question is: Is there any other way code #2 can be written? In short, do we need an instance of parent application (in this case MS-Word) running?
Rich (BB code):
Public Sub TaskUsageInExcel()
Dim tsk As Task
For Each tsk In Tasks 'Gives RTE 429 when run through Excel
Debug.Print tsk.Name
Next tsk
End Sub
I could not find good equivalent of this in Excel. If I've missed it (which is possible) then please tell me, I'd be happy to use it. So I referenced 'Microsoft Word 12.0 Object Library' in Excel and ran the code and it gave me this error 429. Noticeable part was, no instance of word was running at that time.
So I modified the code as below:
Rich (BB code):
Public Sub TaskUsageInExcel2()
Dim wdApp As Word.Application
Dim tsk As Task
'Create hidden instance
Set wdApp = New Word.Application
wdApp.Visible = False
For Each tsk In Tasks
Debug.Print tsk.Name
Next tsk
wdApp.Quit 'close it
End Sub
And it worked.
Now my question is: Is there any other way code #2 can be written? In short, do we need an instance of parent application (in this case MS-Word) running?