Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Adding a popup to specify a filename

I have a macro that reads in a file. The file's name
changes every day when the date is appended. How can I
change my macro so that instead of always calling
MyFile.xls it prompts the user to type in the filename? I
can't make it call in MyFile_with_today's_date.xls because
sometimes I have to run the macro on old files.
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Adding a popup to specify a filename

Steve,

Have a look at the GetOpenFilename method. E.g.,

Dim FName As Variant
FName = Application.GetOpenFilename("Excel Files,*.xls")
If FName = False Then
MsgBox "You didn't choose a file"
Else
MsgBox "You chose file: " & FName
End If

Note that GetOpenFilename doesn't actually open the file. It displays a
standard File Open dialog and returns the name of the file selected by the
user.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com


"Steve" wrote in message
...
I have a macro that reads in a file. The file's name
changes every day when the date is appended. How can I
change my macro so that instead of always calling
MyFile.xls it prompts the user to type in the filename? I
can't make it call in MyFile_with_today's_date.xls because
sometimes I have to run the macro on old files.
Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default Adding a popup to specify a filename

Steve,

Here's some code I got from this forum

Sub GetFile()
Dim FN As String ' for our selected file's name
Dim MyFilter As String ' for the window filter
Dim MyCaption As String ' for the window caption

MyCaption = "Please select a file..."
MyFilter = "Excel (*.xls),*.xls"
'get user to select a file
FN = Application.GetOpenFilename(MyFilter, , MyCaption)
'test for cancelled
If FN = "False" Then
MsgBox "Cancelled"
Else
' do something - for this demo
Dim wb As Workbook
Set wb = Workbooks.Open(FN)
End If
End Sub

--
sb
"Steve" wrote in message
...
I have a macro that reads in a file. The file's name
changes every day when the date is appended. How can I
change my macro so that instead of always calling
MyFile.xls it prompts the user to type in the filename? I
can't make it call in MyFile_with_today's_date.xls because
sometimes I have to run the macro on old files.
Thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding a popup to specify a filename

Dim fName as String
Chdrive "C"
Chdir "C:\Myfolder"
fname = Application.GetOpenFileName()

If ucase(fname) < "FALSE" then
Workbooks.Open fname

End if

See excel vba help on GetOpenFileName
for information on arguments you may use.

--
Regards,
Tom Ogilvy


Steve wrote in message
...
I have a macro that reads in a file. The file's name
changes every day when the date is appended. How can I
change my macro so that instead of always calling
MyFile.xls it prompts the user to type in the filename? I
can't make it call in MyFile_with_today's_date.xls because
sometimes I have to run the macro on old files.
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
Adding date to filename? teepee[_3_] Excel Discussion (Misc queries) 5 April 15th 08 10:05 PM
Adding date for filename Wins07 Excel Discussion (Misc queries) 2 July 31st 07 02:02 PM
Cell("filename") doesn't update to new filename when do save as. Louis Excel Worksheet Functions 2 March 22nd 07 07:27 PM
set filename to <filename-date on open bob engler Excel Worksheet Functions 2 July 13th 06 05:11 AM
"Why did we get here????" popup jtwspoon Excel Discussion (Misc queries) 3 February 4th 05 04:57 AM


All times are GMT +1. The time now is 01:24 PM.

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"