File Search and Select capability in Excel2000

m_lny

New Member
Joined
Feb 24, 2005
Messages
34
I would like to provide a button on my spreadsheet to allow the user to search down thru folders on the c drive to select a file somewhere on the computer. I'm not sure how to reference it, but it should work like "windows explorer" where you can click on a folder to open - then maybe a sub folder until you find the file you would like to select.
The purpose is to import a text file into excel without using a macro, and import text files with different names ( one at a time ).
I think I can mke it work after selecting the fle, but need help in making that selection possible. I have seen references to comdlg32 and msofilepicker but can't do anything with these.

any help will be appreciated

Thank you
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
try
Code:
Sub test()
Dim myDir As String, myFileName As String, x As String
myDir = "c:\temp"
myFileName = "myText.txt"
If Dir(myDir, vbDirectory) = "" Then
     MsgBox "Directory is not exist"
     Exit Sub
End If
x = SearchFile(myDir,myFileName)
If x <> "" Then
     ChDir x
     Application.Dialogs(1).Show
End If
End Sub

Function SearchFile(myDir As String, myFileName As String) As String
Dim fso As Object, myFile As Object, myFolder As Object
Set fso = CreateObject("Scripting.FileSystemObject")
For Each myFile In fso.GetFoler(myDir).Files
     If myFile.Name = myFileName Then
          SearchFile = myDir
          Exit Function
     End If
Next
For Each myFolder In fso.GetFolder(myDir).Subfolders
     SearchFile = SearchFile(myDir & "\" & myFolder.Name)
Next
End Function
 
Upvote 0
Thank you for replying !

I have tried:
fname = Application.GetOpenFilename
Workbooks.Open fname

This opens the selected file in a new workbook. I have an existing workbook and sheet that I would like to add the contents of the file to. I would like to insert the first data into "A3" and then on down thru the A column. The GetOpenFile inserts the data starting at cell A1.

I have searched the Excel help files and can't find anything on GetOpenFile. It does not show up in the index of the help files. I have tried different ways of using workbooks.open, activesheet.open, application.whatever.open, and can't find what to use to insert the data into the active worksheet starting at cell A3.

What I am trying to do is to use something like GetFileOpen to select a text file somewhere on my computer, then inserting the comma delimited data into column A starting at cell A3.

Again, any help would be greatly appreciated.
Thanks
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top