469,927 Members | 2,022 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

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 1154
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.

Similar topics

6 posts views Thread by Matthew Wieder | last post: by
3 posts views Thread by Ian Dunn | last post: by
2 posts views Thread by madeleine | last post: by
3 posts views Thread by pleaseexplaintome_2 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.