ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Open Dialog Box (https://www.excelbanter.com/excel-worksheet-functions/190101-open-dialog-box.html)

MichaelR

Open Dialog Box
 
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

joel

Open Dialog Box
 
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

"MichaelR" wrote:

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



All times are GMT +1. The time now is 10:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com