Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Open File Marco

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Open File Marco


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)


On Sun, 26 Apr 2009 06:13:01 -0700, Elton Law
wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Open File Marco

Hi,

Try this

Workbooks.Open Filename:=Sheets("Sheet1").Range("B4").Value

Mike

"Elton Law" wrote:

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Open File Marco

I have tested ....
Both of you are very strong .... Great ...
Thanks so much !!!

"Chip Pearson" wrote:


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)


On Sun, 26 Apr 2009 06:13:01 -0700, Elton Law
wrote:

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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Marco for printing to file/saving to file [email protected] Excel Programming 0 July 31st 08 03:57 PM
Marco To Save Column A7 As A .txt File. Chris Excel Worksheet Functions 11 May 30th 08 10:20 AM
How: Marco on Pivot Table to save as file up to 300 files [email protected] Excel Programming 4 May 7th 08 06:19 PM
Marco Run on File Close Grant Excel Programming 3 September 30th 04 06:52 PM
save file via Marco Tom Excel Programming 4 July 26th 04 01:29 PM


All times are GMT +1. The time now is 05:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"