end sub if cancel clicked on open file dialog box

yuryyuryyury

New Member
Joined
Jul 3, 2007
Messages
19
I am having trouble ending a macro when the user clicks cancel on the open file dialog box that opens when they run the macro. GetOpenFilename returns false when you click cancel, but I can't get any further than that.

Thank you!

Code:
Sub LoadLV()

Dim wb As Workbook
Dim pickfile As Variant
    
    'Show the open dialog and pass the selected file name to "pickfile"
    pickfile = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", _
        Title:="Choose File", MultiSelect:=False)
    
    'If they have cancelled
    If pickfile = "False" Then End Sub

     
    Set wb = Workbooks.Open(pickfile, True, False) ' open the source workbook with write permissions
    
    wb.Worksheets(1).Range("C6").Copy
    ThisWorkbook.Activate
    ActiveCell.Offset(0, 19).Range("A1").Select
    ActiveSheet.Paste Link:=True
end sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
remove brackets, and replace end wih exit:
if pickfile=False then EXIT sub
 
Upvote 0

Forum statistics

Threads
1,215,388
Messages
6,124,641
Members
449,177
Latest member
Sousanna Aristiadou

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