Problems with File Dialog

RSXchin

Well-known Member
Joined
Oct 23, 2010
Messages
758
Do I need to enable any libraries?
The dialog never comes up, and it treats oFile as a string
Code:
Code:
Set oFile = Application.FileDialog(msoFileDialogFilePicker)
ACTUALLY makes oFile say "Application.FileDialog(msoFileDialogFilePicker)"
The dialog never comes up.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Try

Rich (BB code):
Set oFile = Application.FileDialogs(msoFileDialogFilePicker)
 
Upvote 0
You get a value back in SelectedItems, e.g., (for multi-select)

Code:
[FONT=Consolas][COLOR=#595959]Function GetFileNames(asName() As String) As Long[/COLOR][/FONT]
[COLOR=#595959][FONT=Consolas]    ' Returns a list of file names in dynamic array asName and the count of files returned[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]    Dim nFile As Long[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]    Dim iFile As Long[/FONT][/COLOR]
[FONT=Consolas][COLOR=#595959]    [/COLOR][/FONT]
[COLOR=#595959][FONT=Consolas]    With Application.FileDialog(msoFileDialogFilePicker)[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]        .AllowMultiSelect = True[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]        .Filters.Clear[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]        .Filters.Add "Excel files", "*.xls", 1  ' position 1[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]        .Filters.Add "All Files", "*.*", 2      ' position 2[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]        .FilterIndex = 1                        ' use the first as default[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]        .ButtonName = "Load"                    ' on save/open button[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]        .Title = "Whatever"[/FONT][/COLOR]
[FONT=Consolas][COLOR=#595959]        [/COLOR][/FONT]
[FONT=Consolas][COLOR=#595959]        [/COLOR][/FONT][FONT=Consolas][COLOR=#595959]If .Show Then[/COLOR][/FONT]
[COLOR=#595959][FONT=Consolas]            nFile = .SelectedItems.Count[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]            ReDim asName(1 To nFile)[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]            For iFile = 1 To nFile[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]                asName(iFile) = .SelectedItems(iFile)[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]            Next iFile[/FONT][/COLOR]
[COLOR=#595959][FONT=Consolas]            GetFileNames = nFile[/FONT][/COLOR]
[FONT=Consolas][COLOR=#595959]        [/COLOR][/FONT]
[FONT=Consolas][COLOR=#595959]        [/COLOR][/FONT][FONT=Consolas][COLOR=#595959]Else[/COLOR][/FONT]
[COLOR=#595959][FONT=Consolas]            nFile = 0    ' Cancelled[/FONT][/COLOR]
[FONT=Consolas][COLOR=#595959]        [/COLOR][/FONT][FONT=Consolas][COLOR=#595959]End If[/COLOR][/FONT]
[COLOR=#595959][FONT=Consolas]    End With[/FONT][/COLOR]
[FONT=Consolas][COLOR=#595959]End Function[/COLOR][/FONT]
 
Upvote 0
Try

Rich (BB code):
Set oFile = Application.FileDialogs(msoFileDialogFilePicker)

That gives me a "object doesn't support blah blah blah" error.
And the Office Object 11.0 library is enabled.

Thanks for the quick responses though.
 
Upvote 0

Forum statistics

Threads
1,224,508
Messages
6,179,189
Members
452,893
Latest member
denay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top