Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Excel Getobject error

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 - error saving file & error loading dll TinaF Excel Discussion (Misc queries) 0 July 1st 09 01:49 PM
Error: "Excel encountered an error and had to remove some formatti Carl Excel Discussion (Misc queries) 0 September 18th 06 06:39 PM
Counting instances of found text (Excel error? Or user error?) S Davis Excel Worksheet Functions 5 September 12th 06 04:52 PM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM


All times are GMT +1. The time now is 10:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"