Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel 2007 - error saving file & error loading dll | Excel Discussion (Misc queries) | |||
Error: "Excel encountered an error and had to remove some formatti | Excel Discussion (Misc queries) | |||
Counting instances of found text (Excel error? Or user error?) | Excel Worksheet Functions | |||
Excel 2003 Macro Error - Runtime error 1004 | Excel Discussion (Misc queries) |