Open File Marco

E

Elton Law

Dear Expert,
Say B4 cells contains a text C:\marco\main\help\income2009.xls
How is the VB script so that once I run the marco it will open the file in
accordance to the text in cell please ?
In future, I change the text in B4 to C:\marco\main\help\expense2009.xls
That marco can help me open that file too.
It is not a fixed file name and thus fixed VB script.
File name (to be opened) in cell B4 will be changed from time to time.
Thanks
 
C

Chip Pearson

Try something like

Dim S As String
S = Range("B4").Text
If S <> vbNullString Then
If Dir(S) <> vbNullString Then
Workbook.Open S
Else
Debug.Print "File '" & S & "' does not exist.
End If
Else
Debug.Print "B4 is blank"
End If

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 

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