store error messages

ram_Sathish

New Member
Joined
Jun 12, 2006
Messages
15
Hi All,

I tried storing the msgbox using the following code, but it did not work.
dim s
s=msgbox("Hi")

it return the s value as 1


I tried storing the error message which was declared (using msgbox) into excel file from vb application. But i could store it, it had open the excel application but i could not store the data into the sheets.

can any one please help me.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

SydneyGeek

MrExcel MVP
Joined
Aug 5, 2003
Messages
12,251
Hi Ram,

I'm not sure what you are trying to do here. Why do you want to store the MsgBox result?

What you are doing here is effectively doing a test.
s=MsgBox("Hi") will very likely evaluate as True, which is 1 in Excel.

If you can provide a bit more information on what you need to achieve, we will be able to help you.

Denis
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,304
Office Version
  1. 365
Platform
  1. Windows
Ram

Like Denis I'm curious as to what you are actually wanting to do.

Could you explain further?

Denis

The code is not doing a comparison it's setting s to whatever value is returned by the message box.

In the OP's code the message box will only display the default OK button, vbOK = 1 so s = 1.

A better example might be this.
Code:
s = MsgBox("Hi", vbOKCancel)
MsgBox s
If you hit OK, s=1, if you hit Cancel it's 2.
 

SydneyGeek

MrExcel MVP
Joined
Aug 5, 2003
Messages
12,251
Hi Norie,

Yes I had forgotten about the MsgBox value returns. Thanks for the heads-up.

Denis
 

Forum statistics

Threads
1,141,629
Messages
5,707,506
Members
421,511
Latest member
mgroah1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top