ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Message prompt in VBA (https://www.excelbanter.com/excel-programming/312544-message-prompt-vba.html)

ltong

Message prompt in VBA
 
Hi,

Please assist me on how to write an excel VBA code to prompt a message
" No sheet is to be delete, OK" instead of prompting a VBA error
message when I accidentally run a DeleteSheet macro, which had already
deleted all sheets in a workbook.

With this additional codes so that the DeleteSheet macro can be run
more smoothly.


Thanks
Regards
Lenard

Frank Kabel

Message prompt in VBA
 
Hi
do you mean
msgbox?

--
Regards
Frank Kabel
Frankfurt, Germany

"ltong" schrieb im Newsbeitrag
om...
Hi,

Please assist me on how to write an excel VBA code to prompt a

message
" No sheet is to be delete, OK" instead of prompting a VBA error
message when I accidentally run a DeleteSheet macro, which had

already
deleted all sheets in a workbook.

With this additional codes so that the DeleteSheet macro can be run
more smoothly.


Thanks
Regards
Lenard



Geof Wyght[_2_]

Message prompt in VBA
 
Lenard,
I believe a workbook must have at least 1 worksheet. So
your sub could have something like:
If ThisWorkbook.Worksheets.Count 1 Then
'run your deletesheets sub
Else
MsgBox prompt:="This worrkbook must have at least 1 sheet."
End If

Geof.
-----Original Message-----
Hi,

Please assist me on how to write an excel VBA code to

prompt a message
" No sheet is to be delete, OK" instead of prompting a

VBA error
message when I accidentally run a DeleteSheet macro,

which had already
deleted all sheets in a workbook.

With this additional codes so that the DeleteSheet macro

can be run
more smoothly.


Thanks
Regards
Lenard
.


ltong

Message prompt in VBA
 
Hi all,

Frank, yes it is a msgbox and I got the VBA code from Geof

Thank you, Geof and it works.


By the way, I need another VBA code to prompt a message again " Sorry,
the selected sheet for deletion is not found, OK " ? and it ends the
VBA code instead of prompting VBA error .

Regards
Lenard



"Geof Wyght" wrote in message ...
Lenard,
I believe a workbook must have at least 1 worksheet. So
your sub could have something like:
If ThisWorkbook.Worksheets.Count 1 Then
'run your deletesheets sub
Else
MsgBox prompt:="This worrkbook must have at least 1 sheet."
End If

Geof.
-----Original Message-----
Hi,

Please assist me on how to write an excel VBA code to

prompt a message
" No sheet is to be delete, OK" instead of prompting a

VBA error
message when I accidentally run a DeleteSheet macro,

which had already
deleted all sheets in a workbook.

With this additional codes so that the DeleteSheet macro

can be run
more smoothly.


Thanks
Regards
Lenard
.


Township of East Hanover

Message prompt in VBA
 
Display your own Run Time Errors:

Sub MyMacro()
On Error Goto MyError
'Your code here

Exit sub
MyError:
MsgBox "An error has occured"
End Sub

For more info go to http://www.ozgrid.com/VBA/ExcelVBAErrors.htm

"ltong" wrote in message
m...
Hi all,

Frank, yes it is a msgbox and I got the VBA code from Geof

Thank you, Geof and it works.


By the way, I need another VBA code to prompt a message again " Sorry,
the selected sheet for deletion is not found, OK " ? and it ends the
VBA code instead of prompting VBA error .

Regards
Lenard



"Geof Wyght" wrote in message
...
Lenard,
I believe a workbook must have at least 1 worksheet. So
your sub could have something like:
If ThisWorkbook.Worksheets.Count 1 Then
'run your deletesheets sub
Else
MsgBox prompt:="This worrkbook must have at least 1 sheet."
End If

Geof.
-----Original Message-----
Hi,

Please assist me on how to write an excel VBA code to

prompt a message
" No sheet is to be delete, OK" instead of prompting a

VBA error
message when I accidentally run a DeleteSheet macro,

which had already
deleted all sheets in a workbook.

With this additional codes so that the DeleteSheet macro

can be run
more smoothly.


Thanks
Regards
Lenard
.





All times are GMT +1. The time now is 03:13 AM.

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