PDA

View Full Version : Custom Get Open File Dialog



mcwsky09
04-08-2012, 09:30 AM
I am running into what appears to be a limitation of the built in GetOpenFilename function - in that I cannot change the buttons.

After the user selects a File to open - I pop up a question to either Append to Existing or Replace Existing - I would prefer to have that be options directly on the open file dialog.

If there is no way to edit the built in dialog - then perhaps I need to create my own Open File dialog entirely?

Or another approach would be to have a separate Erase Existing button that can be fired off first - and have the get open file always use my append method. Which may be the route I end up with - since I will be building a third option - Insert as New - meaning that I want to have the option to add a new worksheet such that I can have a new page for a new location for example.

If anyone any point me to a way to customize the built in dialog - or code that is already written for a fully customized Get File routine that would be helpful. thanks.

Paul_Hossler
04-08-2012, 11:29 AM
On Line help



ButtonTextOptionalVariantMacintosh only.

Unless you're using a Mac, I think you're out of luck

Paul

Kenneth Hobs
04-08-2012, 11:41 AM
You can use a Userform to set the options.

This method lets you name the OK button. Once the filename(s) is selected, your code can do whatever you like. You can create various versions to Append, Replace, or whatever.

Sub Test()
MsgBox FileOpen("x:\", "Kens Files", "*.xls; *.xlsx; *.xlsm")
End Sub

Function FileOpen(initialFilename As String, _
Optional sDesc As String = "Excel (*.xls)", _
Optional sFilter As String = "*.xls") As String
With Application.FileDialog(msoFileDialogOpen)
.ButtonName = "&Open"
.initialFilename = initialFilename
.Filters.Clear
.Filters.Add sDesc, sFilter, 1
.Title = "File Open"
.AllowMultiSelect = False
If .Show = -1 Then FileOpen = .SelectedItems(1)
End With
End Function

Paul_Hossler
04-08-2012, 04:21 PM
That is handy

Paul

mcwsky09
04-10-2012, 01:41 PM
I am developing on Mac but my users will be mostly Windows.

That might be slightly more elegant that what I am using - which is calling the FileOpen to get the file name - then popping up a dialog to ask.

What I would prefer is that on the File Open dialog - instead of Open and Cancel buttons - to have Insert - Append - Replace - Cancel.

but I suspect what I will do is make the File Open always append - and separately add buttons for Clear Existing - and Insert Page.