473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1267
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.