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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
remove brackets, and replace end wih exit:
if pickfile=False then EXIT sub
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,543
Members
449,089
Latest member
davidcom

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