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

Doing your way:
Set WB = XLApp.Workbooks.Open(FileName:="C:\whatever.xls")

WB is NOT set

I have found the following way which works, but I am not sure whether it is
the right one:

If FileExists(XLSheetFullTitle) = True Then
Set moExcelWS =
CreateObject(moExcelApp.Workbooks.Open(XLSheetFull PathTitle))
'moExcelWS is not set but it loads the file
' then I do whats below and moExcelWS is set.

If moExcelWS Is Nothing Then
Set moExcelWS =
moExcelApp.Workbooks(ExSheetTitle).Worksheets(Left (ExSheetTitle,
Len(ExSheetTitle) - 4))
End If

Jack

"Chip Pearson" wrote in message
...
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