Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default macro to search & open file

If i type a file name in cell "A2", is there a way to pick up that file name
from cell A2, look in a specific location and open it? and if not found,
display a message that file was not found?

Cheers,
Mayte
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default macro to search & open file

Mayte,

Right-click on the sheet tab and choose View Code. In that code
window, paste the following

Private Sub Worksheet_Change(ByVal Target As Range)
Dim FName As String
Dim Path As String
Dim WB As Workbook
If Target.Address < "$A$2" Then
Exit Sub
End If
' Change Path to the desired folder name
Path = "C:\Test" '<<<< CHANGE
FName = Path & "\" & Target.Text
If Dir(FName) = vbNullString Then
' file does not exist
End If
' ensure that the workbook is not already open
For Each WB In Workbooks
If StrComp(FName, WB.FullName, vbTextCompare) = 0 Then
Exit Sub
End If
Next WB
Workbooks.Open Filename:=FName
End Sub


This will look at cell A2 and open the file if it exists and is not
already open. Change the Path value as necessary.

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




On Tue, 10 Mar 2009 15:02:01 -0700, Mayte
wrote:

If i type a file name in cell "A2", is there a way to pick up that file name
from cell A2, look in a specific location and open it? and if not found,
display a message that file was not found?

Cheers,
Mayte

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default macro to search & open file

Thanks a lot !!!

one more favour ..anyway to search in a folder and all sub-folders?

cheers,
mayte
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
No text search from File|Open in Excel 2007? BrianG[_2_] New Users to Excel 1 June 15th 09 09:02 PM
what happened to file, open, tools, search? maydog Excel Discussion (Misc queries) 1 June 19th 08 07:46 PM
Open Another File to Search and Replace Text Ricky Pang Excel Programming 1 August 15th 06 05:55 PM
Macro to open search box? PSutherby Excel Programming 1 June 7th 06 01:19 PM


All times are GMT +1. The time now is 04:46 PM.

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

About Us

"It's about Microsoft Excel"