ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Msg Box - User Entry Validation (https://www.excelbanter.com/excel-programming/336542-msg-box-user-entry-validation.html)

ACase

Msg Box - User Entry Validation
 
Hello,

I am writing some vb code which will save a workbook

WB.SaveAs ("MyExcelWorkbook.xls") - Now if I have already run this Macro MS
Excel prompts the user saying "MyExcelWorkbook.xls" already exists do you
want to override. Yes / No / Cancel

If the user clicks 'Yes' everything is fine. However if the user clicks No
or Cancel the code crashes. How do I build in this validation.

Any help would be much appreciated.

AC




Tom Ogilvy

Msg Box - User Entry Validation
 
Dim ans as Long

ans = vbYes
If dir( "MyExcelworkbook.xls") < "" then _
ans = Msgbox( "Overwrite existing MyExcelworkbooks.xls",vbYesNo)
if ans = vbYes then
WB.SaveAs ("MyExcelWorkbook.xls")
End if

--
Regards,
Tom Ogilvy

"ACase" wrote in message
...
Hello,

I am writing some vb code which will save a workbook

WB.SaveAs ("MyExcelWorkbook.xls") - Now if I have already run this Macro

MS
Excel prompts the user saying "MyExcelWorkbook.xls" already exists do you
want to override. Yes / No / Cancel

If the user clicks 'Yes' everything is fine. However if the user clicks

No
or Cancel the code crashes. How do I build in this validation.

Any help would be much appreciated.

AC







All times are GMT +1. The time now is 08:09 PM.

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