Easy Question - Opening a workbook

D

Dave Ramage

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top