ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Easy Question - Opening a workbook (https://www.excelbanter.com/excel-programming/273286-easy-question-opening-workbook.html)

Dave Ramage[_2_]

Easy Question - Opening a workbook
 
Greg, try this:

Sub demo()
Dim strPath As String
Dim wbW As Workbook

'get path and name of workbook containing macro
strPath = ThisWorkbook.FullName
'extract path only
strPath = Left(strPath, InStrRev(strPath, "\"))

'open another workbook to this folder:
Set wbW = Workbooks.Open(strPath & "MyBook.xls")
End Sub

Note that if the workwork containing the code has not been
saved yet then the second strPath statement will return ""
and you'll get an error openning the workbook.

Cheers,
Dave.
-----Original Message-----
Hi,

I need to know the syntax for opening a workbook in the
same folder from which the workbook running the macro is
in.

The overall path of the files will change but they will
always be in the same folder.

Thanks in advance

Greg
.



All times are GMT +1. The time now is 10:22 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com