PC Review


Reply
Thread Tools Rate Thread

Answering Message boxes

 
 
=?Utf-8?B?aXNiam9ybmVu?=
Guest
Posts: n/a
 
      26th Oct 2006
Hello,

I have a question on how to answer message boxes programmatically.
For example: Answering [No] when closing a file and the message box prompts
me to save.
I've programmed in Lotus before and I used this command:
AnswerMsgBox (Value)

The command had to be entered on the line preceding the message box
AnswerMsgBox No
Application.Quit
In this example the program does not prompt to save before closing.

Is there a similar command in Excel?

Thanx!
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q2hhZEY=?=
Guest
Posts: n/a
 
      26th Oct 2006

Hello,

You might want to consider this approach:

Dim myAnswer as String

myAnswer = MsgBox "Do you want to Save", vbYesNo

if myAnswer = vbYes then
.... 'do something
else
... ' do something else ...
end if

There are several options you can do with MsgBox.

Hope this helps,
Chad


"isbjornen" wrote:

> Hello,
>
> I have a question on how to answer message boxes programmatically.
> For example: Answering [No] when closing a file and the message box prompts
> me to save.
> I've programmed in Lotus before and I used this command:
> AnswerMsgBox (Value)
>
> The command had to be entered on the line preceding the message box
> AnswerMsgBox No
> Application.Quit
> In this example the program does not prompt to save before closing.
>
> Is there a similar command in Excel?
>
> Thanx!

 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      26th Oct 2006
> Dim myAnswer as String

This is incorrect. You should use

Dim myAnswer as Long
or, better (in Excel 2000 and later),
Dim myAnswer As VbMsgBoxResult


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com
(email address is on the web site)



"ChadF" <(E-Mail Removed)> wrote in message
news:B9B0A7A5-A19B-4812-B4DC-(E-Mail Removed)...
>
> Hello,
>
> You might want to consider this approach:
>
> Dim myAnswer as String
>
> myAnswer = MsgBox "Do you want to Save", vbYesNo
>
> if myAnswer = vbYes then
> .... 'do something
> else
> ... ' do something else ...
> end if
>
> There are several options you can do with MsgBox.
>
> Hope this helps,
> Chad
>
>
> "isbjornen" wrote:
>
>> Hello,
>>
>> I have a question on how to answer message boxes programmatically.
>> For example: Answering [No] when closing a file and the message box
>> prompts
>> me to save.
>> I've programmed in Lotus before and I used this command:
>> AnswerMsgBox (Value)
>>
>> The command had to be entered on the line preceding the message box
>> AnswerMsgBox No
>> Application.Quit
>> In this example the program does not prompt to save before closing.
>>
>> Is there a similar command in Excel?
>>
>> Thanx!



 
Reply With Quote
 
Susan
Guest
Posts: n/a
 
      26th Oct 2006
or, to avoid "dim"ing anything at all, you can use an if-then
construct.

If Msgbox ("Do you want to quit?",vbYesNo + vbInformation) = vbNo Then
Exit Sub 'or close file, or whatever
Else
(whatever)
End If

susan
(who must be moving up in the excel
world if she's adding info to mvp's!!!)
ha ha

 
Reply With Quote
 
=?Utf-8?B?Q2hhZEY=?=
Guest
Posts: n/a
 
      26th Oct 2006
Indeed. Thanks Chip.


"Chip Pearson" wrote:

> > Dim myAnswer as String

>
> This is incorrect. You should use
>
> Dim myAnswer as Long
> or, better (in Excel 2000 and later),
> Dim myAnswer As VbMsgBoxResult
>
>
> --
> Cordially,
> Chip Pearson
> Microsoft MVP - Excel
> www.cpearson.com
> (email address is on the web site)
>
>
>
> "ChadF" <(E-Mail Removed)> wrote in message
> news:B9B0A7A5-A19B-4812-B4DC-(E-Mail Removed)...
> >
> > Hello,
> >
> > You might want to consider this approach:
> >
> > Dim myAnswer as String
> >
> > myAnswer = MsgBox "Do you want to Save", vbYesNo
> >
> > if myAnswer = vbYes then
> > .... 'do something
> > else
> > ... ' do something else ...
> > end if
> >
> > There are several options you can do with MsgBox.
> >
> > Hope this helps,
> > Chad
> >
> >
> > "isbjornen" wrote:
> >
> >> Hello,
> >>
> >> I have a question on how to answer message boxes programmatically.
> >> For example: Answering [No] when closing a file and the message box
> >> prompts
> >> me to save.
> >> I've programmed in Lotus before and I used this command:
> >> AnswerMsgBox (Value)
> >>
> >> The command had to be entered on the line preceding the message box
> >> AnswerMsgBox No
> >> Application.Quit
> >> In this example the program does not prompt to save before closing.
> >>
> >> Is there a similar command in Excel?
> >>
> >> Thanx!

>
>
>

 
Reply With Quote
 
=?Utf-8?B?aXNiam9ybmVu?=
Guest
Posts: n/a
 
      26th Oct 2006
Thanks, but I'm trying to avoid having a default Windows messagebox popping
up and pausing the macro. In the example below, I don't want to save before
exiting the program, i.e. I want the answer to be [No] without clicking.

"ChadF" wrote:

>
> Hello,
>
> You might want to consider this approach:
>
> Dim myAnswer as String
>
> myAnswer = MsgBox "Do you want to Save", vbYesNo
>
> if myAnswer = vbYes then
> .... 'do something
> else
> ... ' do something else ...
> end if
>
> There are several options you can do with MsgBox.
>
> Hope this helps,
> Chad
>
>
> "isbjornen" wrote:
>
> > Hello,
> >
> > I have a question on how to answer message boxes programmatically.
> > For example: Answering [No] when closing a file and the message box prompts
> > me to save.
> > I've programmed in Lotus before and I used this command:
> > AnswerMsgBox (Value)
> >
> > The command had to be entered on the line preceding the message box
> > AnswerMsgBox No
> > Application.Quit
> > In this example the program does not prompt to save before closing.
> >
> > Is there a similar command in Excel?
> >
> > Thanx!

 
Reply With Quote
 
Susan
Guest
Posts: n/a
 
      26th Oct 2006
then why have a message box at all?
the purpose of the message box is to either inform the
user of something, or get their input as to a simple
yes/no/cancel-type decision.
if you want the code to do something automatically,
then program it in the code.

or am i missing the point entirely?
susan

 
Reply With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      26th Oct 2006
What you really want to do is to avoid the message box entirely. You can do
this by adding the following to the ThisWorkbook module (Right click the XL
icon next to the word file and select view code). Past this in the code
window...

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Saved = True
End Sub

XL amintains a flag which lets it know if a save is required. by executing
this in the before close event we are setting that flag to saved so that XL
now beleives that there is nothing to save and it will exet without the
prompt...
--
HTH...

Jim Thomlinson


"isbjornen" wrote:

> Thanks, but I'm trying to avoid having a default Windows messagebox popping
> up and pausing the macro. In the example below, I don't want to save before
> exiting the program, i.e. I want the answer to be [No] without clicking.
>
> "ChadF" wrote:
>
> >
> > Hello,
> >
> > You might want to consider this approach:
> >
> > Dim myAnswer as String
> >
> > myAnswer = MsgBox "Do you want to Save", vbYesNo
> >
> > if myAnswer = vbYes then
> > .... 'do something
> > else
> > ... ' do something else ...
> > end if
> >
> > There are several options you can do with MsgBox.
> >
> > Hope this helps,
> > Chad
> >
> >
> > "isbjornen" wrote:
> >
> > > Hello,
> > >
> > > I have a question on how to answer message boxes programmatically.
> > > For example: Answering [No] when closing a file and the message box prompts
> > > me to save.
> > > I've programmed in Lotus before and I used this command:
> > > AnswerMsgBox (Value)
> > >
> > > The command had to be entered on the line preceding the message box
> > > AnswerMsgBox No
> > > Application.Quit
> > > In this example the program does not prompt to save before closing.
> > >
> > > Is there a similar command in Excel?
> > >
> > > Thanx!

 
Reply With Quote
 
=?Utf-8?B?aXNiam9ybmVu?=
Guest
Posts: n/a
 
      26th Oct 2006
Thanks, this answer half of my question - specific for not saving a workbook.
However, what I'm looking for is a generic command/statement that can take
care of every situation of a default Windows Message. Sometimes I might want
to answer [OK], or [Retry] etc. depending on the situation.

Is there a generic command/statement?


"Jim Thomlinson" wrote:

> What you really want to do is to avoid the message box entirely. You can do
> this by adding the following to the ThisWorkbook module (Right click the XL
> icon next to the word file and select view code). Past this in the code
> window...
>
> Private Sub Workbook_BeforeClose(Cancel As Boolean)
> ThisWorkbook.Saved = True
> End Sub
>
> XL amintains a flag which lets it know if a save is required. by executing
> this in the before close event we are setting that flag to saved so that XL
> now beleives that there is nothing to save and it will exet without the
> prompt...
> --
> HTH...
>
> Jim Thomlinson
>
>
> "isbjornen" wrote:
>
> > Thanks, but I'm trying to avoid having a default Windows messagebox popping
> > up and pausing the macro. In the example below, I don't want to save before
> > exiting the program, i.e. I want the answer to be [No] without clicking.
> >
> > "ChadF" wrote:
> >
> > >
> > > Hello,
> > >
> > > You might want to consider this approach:
> > >
> > > Dim myAnswer as String
> > >
> > > myAnswer = MsgBox "Do you want to Save", vbYesNo
> > >
> > > if myAnswer = vbYes then
> > > .... 'do something
> > > else
> > > ... ' do something else ...
> > > end if
> > >
> > > There are several options you can do with MsgBox.
> > >
> > > Hope this helps,
> > > Chad
> > >
> > >
> > > "isbjornen" wrote:
> > >
> > > > Hello,
> > > >
> > > > I have a question on how to answer message boxes programmatically.
> > > > For example: Answering [No] when closing a file and the message box prompts
> > > > me to save.
> > > > I've programmed in Lotus before and I used this command:
> > > > AnswerMsgBox (Value)
> > > >
> > > > The command had to be entered on the line preceding the message box
> > > > AnswerMsgBox No
> > > > Application.Quit
> > > > In this example the program does not prompt to save before closing.
> > > >
> > > > Is there a similar command in Excel?
> > > >
> > > > Thanx!

 
Reply With Quote
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      26th Oct 2006
Reading carefully what isbjornen wrote, I believe the line he wants to use is:
ThisWorkbook.Saved = True

This prevents the Excel software from automatically asking if you want to
save. To incorporate it into your code in response to a MsgBox you would
most likely have to use an If statement like:
If MsgBoxResponse = vbNo Then
ThisWorkbook.Saved = True
End If

Maybe we are confusing Message Box and Dialog Box?

"isbjornen" wrote:

> Thanks, but I'm trying to avoid having a default Windows messagebox popping
> up and pausing the macro. In the example below, I don't want to save before
> exiting the program, i.e. I want the answer to be [No] without clicking.
>
> "ChadF" wrote:
>
> >
> > Hello,
> >
> > You might want to consider this approach:
> >
> > Dim myAnswer as String
> >
> > myAnswer = MsgBox "Do you want to Save", vbYesNo
> >
> > if myAnswer = vbYes then
> > .... 'do something
> > else
> > ... ' do something else ...
> > end if
> >
> > There are several options you can do with MsgBox.
> >
> > Hope this helps,
> > Chad
> >
> >
> > "isbjornen" wrote:
> >
> > > Hello,
> > >
> > > I have a question on how to answer message boxes programmatically.
> > > For example: Answering [No] when closing a file and the message box prompts
> > > me to save.
> > > I've programmed in Lotus before and I used this command:
> > > AnswerMsgBox (Value)
> > >
> > > The command had to be entered on the line preceding the message box
> > > AnswerMsgBox No
> > > Application.Quit
> > > In this example the program does not prompt to save before closing.
> > >
> > > Is there a similar command in Excel?
> > >
> > > Thanx!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Outolook 2003 is slow when answering message Seiya Microsoft Outlook 4 19th Mar 2010 01:27 PM
how do you automatically delete original message after answering. Hesston_Don Microsoft Outlook Discussion 2 16th Mar 2008 07:26 AM
deleting original message when answering email =?Utf-8?B?cGF0IGluIGdlb3JnZXRvd24=?= Windows Vista Mail 2 22nd Jun 2007 12:53 AM
Missing text in message boxes & list boxes Brian Mitchell Microsoft VB .NET 3 18th Jun 2005 08:41 AM
message won't forward when message has small boxes =?Utf-8?B?QnJvd25QYXJr?= Microsoft Outlook Discussion 0 22nd Apr 2005 11:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:38 AM.