Open Dialog Appears Twice in VBA

sax2play

Board Regular
Joined
Mar 13, 2021
Messages
51
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

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Alex Blakenburg

Well-known Member
Joined
Feb 23, 2021
Messages
2,012
Office Version
  1. 365
Platform
  1. Windows
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.
 
Solution

sax2play

Board Regular
Joined
Mar 13, 2021
Messages
51
Office Version
  1. 2016
Platform
  1. Windows
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!
 

Alex Blakenburg

Well-known Member
Joined
Feb 23, 2021
Messages
2,012
Office Version
  1. 365
Platform
  1. Windows
No problem. Glad I could help. Thank you for letting me know.
 

Forum statistics

Threads
1,143,675
Messages
5,720,237
Members
422,271
Latest member
xbaca

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
Top