View Single Post
  #4   Report Post  
Posted to microsoft.public.vb.general.discussion,microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Run time '429' : ActveX component can't create object

Using the automation, how can I start Excel application with the specified
spreadsheet title?


Once you've got a reference to Excel, you can open up any file you want. Use
code like the following:

Dim WB As Excel.Workbook
Set WB = XLApp.Workbooks.Open(FileName:="C:\whatever.xls")

where XLApp is a reference to the Excel Application object.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"Jack" <replyto@it wrote in message
...
Mike,
Thank you very much for your reply.
One more question:
Using the automation, how can I start Excel application with the specified
spreadsheet title?
Jack
"MikeD" wrote in message
...

"Jack" <replyto@it wrote in message
...
My code checks whether Excel app is open by using this line of code:


Open_Excel_App:
Debug.Print "Excel app NOT found!"
On Error GoTo 0
rtn = ShellExecute(Me.hwnd, "Open", "excel.exe", vbNullString,
App.Path, vbNormalFocus)



Don't start Excel that way. Use Automation to start it. Here's a MUCH
simpler way (using late-binding) to do what your wanting:

Option Explicit
Private moExcelApp As Object


On Error Resume Next 'TEMPORARILY ignore errors
Set moExcelApp = GetObject(, "Excel.Application")
On Error GoTo EH 'Resume normal error handling

If moExcelApp Is Nothing Then
Set moExcelApp = CreateObject("Excel.Application")
moExcelApp.Visible = True 'if you want Excel to be visible at this
point
End If

On Error GoTo EH 'Resume normal error handling

Exit Sub 'or Function as the case may be


This gives you a reference to Excel without having to shell to it and
using FindWindow and all the rest of the "garbage" you're doing to
accomplish this.

--
Mike
Microsoft MVP Visual Basic