Open Dialog Appears Twice in VBA

sax2play

Board Regular
Joined
Mar 13, 2021
Messages
63
Office Version
  1. 2016
Platform
  1. Windows
Hello All!

I have a macro that pulls in information from another file via a FileDialog prompt. I added a condition to avoid an error if a file is not selected and now it always prompts to select the file twice or click "cancel" twice. Any thoughts??

VBA Code:
Dim fd As Office.FileDialog
    Dim strFile As String
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
        .Filters.Clear
        .Filters.Add "Excel Files", "*.xlsm?", 1
        .Title = "Choose a File"
        .AllowMultiSelect = False
        .InitialFileName = "C:\Users\" & Environ("UserName") & "\Desktop"
        If .Show = True Then
            strFile = .SelectedItems(1)
        Workbooks.Open Filename:=strFile, UpdateLinks:=3
        End If
        If .Show = False Then GoTo SaveAs
    End With
    Dim WA As Workbook: Set WA = ActiveWorkbook
    WA.Sheets("Review").Copy After:=WB.Sheets("Config_Review")
    WA.Close SaveChanges:=False

Thanks!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
The “.Show” command calls up the FilePicker dialogue box and you are using “show” twice.
Get rid of
VBA Code:
  If .Show = False Then GoTo SaveAs
And put the “GoTo SaveAs” in the else statement of the previous If statement.
 
Upvote 0
Solution
The “.Show” command calls up the FilePicker dialogue box and you are using “show” twice.
Get rid of
VBA Code:
  If .Show = False Then GoTo SaveAs
And put the “GoTo SaveAs” in the else statement of the previous If statement.
That worked like a charm, thanks Alex!
 
Upvote 0

Forum statistics

Threads
1,214,431
Messages
6,119,462
Members
448,899
Latest member
maplemeadows

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