Hello All,
I've had no luck searching for similar posting, so here I am...
I'm attempting to create a macro where by a particular file will be opened as defined by the code, but if it cannot find it to open the dialog box for the user to select the file. The code I have below works, except if I click cancel on the open dialog box, the macro continues on regardless and executes on whatever file is currently open (not good). My question is, how do I end the sub if I click cancel?
Code:
Sub report()
Dim sfile As String
sfile = Dir("C:\report.xls")
If sfile <> "" Then Workbooks.Open Filename:="C:\report.xls" _
Else Application.Dialogs(xlDialogFindFile).Show
'simple formating macro below...
End Sub
Thanks you in advance for any assistance
Inpttrdr (ignorant noob)
I've had no luck searching for similar posting, so here I am...
I'm attempting to create a macro where by a particular file will be opened as defined by the code, but if it cannot find it to open the dialog box for the user to select the file. The code I have below works, except if I click cancel on the open dialog box, the macro continues on regardless and executes on whatever file is currently open (not good). My question is, how do I end the sub if I click cancel?
Code:
Sub report()
Dim sfile As String
sfile = Dir("C:\report.xls")
If sfile <> "" Then Workbooks.Open Filename:="C:\report.xls" _
Else Application.Dialogs(xlDialogFindFile).Show
'simple formating macro below...
End Sub
Thanks you in advance for any assistance
Inpttrdr (ignorant noob)