Dialog Box Question

MrKremrik

Board Regular
Joined
Jul 16, 2012
Messages
56
Hi again,

Does anyone know the code for a - I don't know what it's called - "dialog box" in excel? I need to have a user enter the name of a file, have the code add ".xls" to the end, and then use it to open that file and use it for the address of a vlookup. In a perfect world, I'd love it to spit out an error message if it can't find the file and have the user try again. Thanks in advance!!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try something like this...

Code:
[COLOR=darkblue]Sub[/COLOR] Select_a_File()

    [COLOR=darkblue]Dim[/COLOR] wb [COLOR=darkblue]As[/COLOR] Workbook

        [COLOR=green]' Prompt user to select a file[/COLOR]
        [COLOR=darkblue]With[/COLOR] Application.FileDialog(msoFileDialogOpen)
        
            .InitialFileName = ThisWorkbook.Path              [COLOR=green]' Default path[/COLOR]
            .FilterIndex = 3
            .Title = "Please Select a File"
            .ButtonName = "Open"
            .AllowMultiSelect = [COLOR=darkblue]False[/COLOR]
            .Show
            [COLOR=darkblue]If[/COLOR] .SelectedItems.Count = 0 [COLOR=darkblue]Then[/COLOR] [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]Sub[/COLOR]   [COLOR=green]' User clicked cancel[/COLOR]
            
            [COLOR=darkblue]Set[/COLOR] wb = Workbooks.Open(Filename:=.SelectedItems(1))
            
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Upvote 0
Okay it worked, but will I be able to use that file in a vlookup? something like =vlookup($A2, 'wb'!$A$2:$H$1000, 2, false) ? that's the big thing I need it to do.
 
Upvote 0

Forum statistics

Threads
1,216,671
Messages
6,132,041
Members
449,697
Latest member
bororob85

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