ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Prompt user to select file with default file selected dialog (https://www.excelbanter.com/excel-programming/277009-re-prompt-user-select-file-default-file-selected-dialog.html)

Bruce Cooley

Prompt user to select file with default file selected dialog
 
Gary:

Have you played with the FilePicker dialog? Here are some lines I excerpted
from some code I used it in. If I recall correctly, you can set the path
and filename that shows up in the dialog box. I have it set to *.*, but
this might get you started. Look up FilePicker in VBA help.

Dim fd As FileDialog
Set fd = Application.FileDialog(Type:=msoFileDialogFilePick er)
With fd
.Title = "Select a file"
.Filters.Clear
.Filters.Add "Excel Workbooks", "*.xls"
.InitialFileName = "*.*"
If .Show = -1 Then ' user pressed the action button.
strNewPathFilename = fd.SelectedItems.Item(1)
etc.

Bruce Cooley


"Gary Gepner" wrote in message
om...
: I want to prompt user with a windows dialog from vba and want user to
: pick a file, but I want to be able to specify file directory and name.
:
: I looked at GetOpenFilename, preceded by a chdir command, but I am
: not able to default to a specific name.
:
: ChDir ActiveWorkbook.Path
: GlbGetFileName = Application.GetOpenFilename _
: (fileFilter:="Text Files (*.txt),*.txt", _
: FilterIndex:=1, _
: Title:="Choose a directory and file name to run the Report")
: If GlbGetFileName = "False" Then
: Close
: Exit Sub
: End If
:
: I then went back and remembered the GetSaveAsFilename method, might do
: what I want. (it doesn't save a file, just displays the list). This
: works functionally perfectly, but the only problem is it displays a
: Save button.
:
: GlbGetFileName = Application.GetSaveAsFilename _
: (InitialFilename:="c:\bcsits\bcsitsout.txt", _
: fileFilter:="Text Files (*.txt), *.txt", _
: FilterIndex:=1, _
: Title:="Choose a directory and file name to run the Report")
: If GlbGetFileName = "False" Then
: Close
: Exit Sub
: End If
:
: Any suggestions?
:
: Gary Gepner




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

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