By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,645 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,645 IT Pros & Developers. It's quick & easy.

Accessing existing Excel Workbook from complete path

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.