View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bill Lunney Bill Lunney is offline
external usenet poster
 
Posts: 68
Default Excel Getobject error

This should fail when Excel is NOT open. That's because the GetObject line
will generate an error if it can't find an instance of Excel. You're also
defining the loXLS object after calling GetObject. Try this:

Dim loXLS As Excel.Application

On Error Resume Next

Set loXLS = GetObject(, "Excel.Application")
If Err.Number 0 Then
MsgBox "Excel is not running"
End
End If

For i = 1 To loXLS.Workbooks.Count
If loXLS.Workbooks(i).FullName = psFile Then
Exit For
End If
Next i


--

Regards,


Bill Lunney
www.billlunney.com

"Jaya" wrote in message
...
Hi,

i have the following code in VB.
Set loXLS = GetObject(, "Excel.Application")

Dim loXLS As Excel.Application
For i = 1 To loXLS.Workbooks.Count
If loXLS.Workbooks(i).FullName = psFile Then
Exit For
End If
Next i

When a excel file is already open, this fails. And the
loxls.workbooks.count is 0. Can you tell me what could be
the reason?
-Jaya