Open Dialog Box

M

MichaelR

Hi,

I'm trying to write a macro that will update a workbook by importing a sheet
from a computer file that is generated daily. The name of the file is the
date and the time that it was downloaded so it is always going to be
different.

The way that my macro is written now, it asks the user to input the name of
the workbook using the "inputbox" function and then opens that file. I would
like to make the macro even more user friendly by just prompting the user to
double click on the file and then getting the macro to import the worksheet
from the specified workbook. Is this even possible and if so, how would I
write the code for it?

Thank you in advance for your time.
Michael
 
J

Joel

I saw your two postings. Modified my last code to use the DIR() function
with a wildcard (*) to find the file.

FName = ThisWorkbook.Name
Folder = ThisWorkbook.Path
'remove name before .xls
FName = Left(FName, Len(FName) - 4)
InFName = Folder & "\" & FName & ".Txt"

SName = Dir(Folder & "\" & FName & "*.Txt")
If SName <> "" Then

With ActiveSheet.QueryTables.Add(Connection:=SName, _
Destination:=Range("A1"))

.Name = "FName"
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileCommaDelimiter = True
.Refresh BackgroundQuery:=False
End With
Else
MsgBox ("Cannot find File : " & Folder & "\" & FName & "*.Txt")
End If
 

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