LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default getobject error

I solved the problem... There were two instances running.
For some reason it was not getting both the instances. I
killed one of the instance and it worked fine.
Thanks,
Jaya
-----Original Message-----
Jaya,
Move the dim statement before the set statement.

Dim loXLS As Excel.Application
Set loXLS = GetObject("c:\path\filename.xls") ' works if

filename is open.
<<<<<<<<<<<<<<<<<<<<

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


--

John

johnf202 at hotmail dot com


"Bill Lunney" wrote in

message
...
I remember using GetObject a long time ago and came up

against problems
when
multiple version of Excel are running. GetObject will

return the first
instance it finds. If that isn't the one you're

interested in there's
nothing you can do about it (as far as I know).

I used all sorts of wacky things like getting a handle

to a specific
instance by way of the window caption (using the API)

but ran into other
problems best not discussed here.

Bottom line is if you have only one instance of Excel

open and the
GetObject
method does not return it I don't know why. If there

are multiple
instances
open and your getting a handle to one you don't like

you'll need another
approach. I can point you in the right direction if

this is the case.




--

Regards,


Bill Lunney
www.billlunney.com

"jaya" wrote in message
...
I execute the code only when the excel file is open.

The
getobject does not get the instance of the running

excel
application. what could be the reason??
-Jaya

-----Original Message-----
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


.





.



 
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 04:53 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"