Run Time Error 429: ActiveX component can't create object

taurean

Well-known Member
Joined
Jun 17, 2011
Messages
2,190
Office Version
  1. 365
  2. 2016
Platform
  1. 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:
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?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
> "no instance of word was running at that time"

since it is not visible, you will only see it in the task manager

> "In short, do we need an instance of parent application (in this case MS-Word) running? "

you can do this:

Code:
   'if Word is already open, use that instance
   ' ignore errors because if Word is NOT open
   ' we will get one
   On Error Resume Next
   'make assumption that Word is Open
   booCloseWord = False
   Set DocApp = GetObject(, "Word.Application")
   On Error GoTo Proc_Err
     
    'What did we find?...
   If TypeName(DocApp) = "Nothing" Then
      'Word was not open -- create a new instance
      Set DocApp = CreateObject("Word.Application")
      booCloseWord = True
   End If
 
Upvote 0
Thank you very much for your reply, Crystal.

> "no instance of word was running at that time"

since it is not visible, you will only see it in the task manager
What I meant by that line was if you try to use Code#1 you need an instance of Word running Visible / Hidden and if it is not then it will give RTE 429. So I resorted [Code#2] to creating a hidden instance of MS-Word irrespective of whether another instance of Word was running or not.

But I'd missed "GetObject" completely and I can use it in my code. Thank you.

So we need to have an instance of parent application running before we use its objects and methods.
 
Upvote 0
Hi Shrivallabha,

>"
So we need to have an instance of parent application running before we use its objects and methods."

no, my guess is that you only need to reference the library

 
Upvote 0
:
>"
So we need to have an instance of parent application running before we use its objects and methods."

no, my guess is that you only need to reference the library

Hi Crystal,

I'm perplexed as Code#1 doesn't work without an instance of Word [Hidden / Visible]. Am I missing something obvious?
 
Upvote 0

Forum statistics

Threads
1,215,393
Messages
6,124,680
Members
449,180
Latest member
kfhw720

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top