ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Return value for Cancel? (https://www.excelbanter.com/excel-programming/299713-return-value-cancel.html)

Jason Hancock

Return value for Cancel?
 
I've got some operational code for my project, and everything works as
long as there are no deviations from the norm. But, we all know
deviations are going to happen. So, I want to be able to create an
If-Then to check if the user does not select a workbook from the
selection screen. Right now the code is:

UF = Application.GetOpenFilename(FileFilter:="XML Files (*.xml)",
Title:="This Weeks Projections for Marc")
Workbooks.Open Filename:=UF

Set wbUF = Workbooks.Open(Filename:=UF)
UFFN = wbUF.Name

Sheets("Marc").Select
Sheets("Marc").Copy After:=Workbooks("Projection
Summary.xls").Sheets("Summary")
Windows(UFFN).Activate
ActiveWindow.Close


Obviously if the user clicks Cancel, I'm going to get error messages, so
what value does the cancel button return that I can use in an If-Then
statement?


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Bob Phillips[_6_]

Return value for Cancel?
 
UF = Application.GetOpenFilename(FileFilter:="XML Files (*.xml)", _
Title:="This Weeks Projections for Marc")
If UF < "" Then
Workbooks.Open Filename:=UF

Set wbUF = Workbooks.Open(Filename:=UF)
UFFN = wbUF.Name

Sheets("Marc").Select
Sheets("Marc").Copy After:=Workbooks("Projection
Summary.xls").Sheets("Summary")
Windows(UFFN).Activate
ActiveWindow.Close
End If


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Jason Hancock" wrote in message
...
I've got some operational code for my project, and everything works as
long as there are no deviations from the norm. But, we all know
deviations are going to happen. So, I want to be able to create an
If-Then to check if the user does not select a workbook from the
selection screen. Right now the code is:

UF = Application.GetOpenFilename(FileFilter:="XML Files (*.xml)",
Title:="This Weeks Projections for Marc")
Workbooks.Open Filename:=UF

Set wbUF = Workbooks.Open(Filename:=UF)
UFFN = wbUF.Name

Sheets("Marc").Select
Sheets("Marc").Copy After:=Workbooks("Projection
Summary.xls").Sheets("Summary")
Windows(UFFN).Activate
ActiveWindow.Close


Obviously if the user clicks Cancel, I'm going to get error messages, so
what value does the cancel button return that I can use in an If-Then
statement?


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!




Jason Hancock

Return value for Cancel?
 
Thanks!


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


All times are GMT +1. The time now is 02:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com