472,378 Members | 1,299 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,378 software developers and data experts.

Accessing existing Excel Workbook from complete path

Hi all,

I am trying to open a Excel Workbook to check data in worksheets. The
ONLY info I have about the EXCEL file is its entire path. I tried to do
the following, but an exception occurs:
Dim _objXLApp As Excel.ApplicationClass
Dim _objXLFile As Excel.Workbook
Dim _objWorkSheets As Excel.Worksheets
Dim _objXLSheet As Excel.Worksheet
Dim _objRange As Excel.Range
Dim _strPath As String

_strPath = "C:\LOCALDATA\FCP_93.xls"
_objXLApp = New Excel.ApplicationClass
_objXLApp.Visible = False
Try
_objXLFile = _objXLApp.Workbooks(_strPath) 'EXCEPTION HERE:
"Invalid Index"
_objWorkSheets = _objXLFile.Worksheets()

' code continues here
Catch ex As Exception
Show(ex.Message)
End Try

Any idea?

Thanks.

L.

May 2 '06 #1
1 1223
On 2 May 2006 04:47:35 -0700, "Lucile" <lu**********@dexia-am.com> wrote:

¤ Hi all,
¤
¤ I am trying to open a Excel Workbook to check data in worksheets. The
¤ ONLY info I have about the EXCEL file is its entire path. I tried to do
¤ the following, but an exception occurs:
¤
¤
¤ Dim _objXLApp As Excel.ApplicationClass
¤ Dim _objXLFile As Excel.Workbook
¤ Dim _objWorkSheets As Excel.Worksheets
¤ Dim _objXLSheet As Excel.Worksheet
¤ Dim _objRange As Excel.Range
¤ Dim _strPath As String
¤
¤ _strPath = "C:\LOCALDATA\FCP_93.xls"
¤ _objXLApp = New Excel.ApplicationClass
¤ _objXLApp.Visible = False
¤ Try
¤ _objXLFile = _objXLApp.Workbooks(_strPath) 'EXCEPTION HERE:
¤ "Invalid Index"
¤ _objWorkSheets = _objXLFile.Worksheets()
¤
¤ ' code continues here
¤ Catch ex As Exception
¤ Show(ex.Message)
¤ End Try
¤

I believe you're looking for the Open method of the Workbooks collection object.
Paul
~~~~
Microsoft MVP (Visual Basic)
May 2 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Matthew Wieder | last post by:
I have the following requirements: Build a stand-alone C# application that asks the user to click in a cell in an Excel spreadsheet, and then displays the address of that cell in the C#...
1
by: gssstuff | last post by:
Hi I have a need to send data from Access to an existing Excel template that I am using for reporting purposes. The nature of the data in the Access data table does not lend itself to a simple...
3
by: Ian Dunn | last post by:
I'm simply trying to access an instance of Excel that has been opened manually by the user in order to put a few values in the existing sheet. Here's the code I've tried: Dim oXL As...
2
by: madeleine | last post by:
I'm hoping the answer to this is that I'm just doing something silly, but I'm really scratching my head over this one. I'm importing data from multiple workbooks, each workbook has a sheet called...
3
by: dan_roman | last post by:
Hi, I developed a script with a nice interface in Tkinter that allows me to edit some formulas and to generate an Excel worksheet with VBA macros within it. The script runs perfectlly in Office...
5
by: hmiller | last post by:
Hey there folks: I have been trying to get this work for about a week now. I'm new to VBA... I am trying to transfer a populated table in Access to an existing, but blank, Excel worksheet. I...
3
by: pleaseexplaintome_2 | last post by:
using the code below (some parts not included), I create a new excel workbook with spreadheets. I then want to delete a spreadsheet, but a reference remains open and excel stays in task manager...
1
by: DennisBetten | last post by:
First of all, I need to give some credit to Mahesh Chand for providing me with an excellent basis to export data to excel. What does this code do: As the title says, this code is capable of...
16
emibt08
by: emibt08 | last post by:
Hello fellow programmers. I am working on a project that is a windows service. It should open an excel file and read it and it worked good on WinXP SP2 w/ Office 2003. Now the customer upgraded to...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.