Find workbook with code.

  • Thread starter Thread starter coppa
  • Start date Start date
C

coppa

Hi All,
I have about 4 excel workbooks that related to my db.I want to include
these 4 workbooks as one package with my DB.I create a package cause
need to copy to another computer.
Let say their names are MyWorkbook 1,2,3,and 4.

Currently I write the code to open the workbook like below.

Set appXL = CreateObject("Excel.Application")
Set wkb = appXL.Workbooks.Open("C:\MyFolder\MyWorkbook.xls")
Set wks = wkb.Worksheets(1)

But if I copy the package and put it in another computer,mean the code
need to be modified,isn't it?.And I don't want to get busy with that.
I want some code that can catch the the path of the workbook automatically.
Let decide that the workbook must be always placed aside the database ( in
the same
folder with the database ),so that the code will refer to the database path
to
and find the workbook.
How to write the code?
Any kind of help from the expert is greatly appreciated.Many Thank's.
 
coppa said:
Hi All,
I have about 4 excel workbooks that related to my db.I want to include
these 4 workbooks as one package with my DB.I create a package cause
need to copy to another computer.
Let say their names are MyWorkbook 1,2,3,and 4.

Currently I write the code to open the workbook like below.

Set appXL = CreateObject("Excel.Application")
Set wkb = appXL.Workbooks.Open("C:\MyFolder\MyWorkbook.xls")
Set wks = wkb.Worksheets(1)

But if I copy the package and put it in another computer,mean the code
need to be modified,isn't it?.And I don't want to get busy with that.
I want some code that can catch the the path of the workbook
automatically.
Let decide that the workbook must be always placed aside the database ( in
the same
folder with the database ),so that the code will refer to the database
path
to
and find the workbook.
How to write the code?
Any kind of help from the expert is greatly appreciated.Many Thank's.

Dim strPath As String

strPath = Application.CurrentProject.Path
Set appXL = CreateObject("Excel.Application")
Set wkb = appXL.Workbooks.Open(strPath & "\MyWorkbook.xls")

CurrentProject.Path gets you the database path that you mentioned.
 
Back
Top