A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

More MsgBox questions.



 
 
Thread Tools Display Modes
  #1  
Old December 21st, 2009, 05:42 PM posted to microsoft.public.excel.misc
Pete[_28_]
external usenet poster
 
Posts: 1
Default More MsgBox questions.

I am attempting to use the Msgbox function with the Ok/Cancel buttons. the
code I have written thus far is below:

Msgbox("Message",1)

If ans = vbOk then call [subroutine]
If ans = vbCancel the exit sub

end if

end sub

The subroutine does not work when the "Ok" button is used. I have tried
other variations on this to no avail. Could anyone please assist?
--

Thanks,
Pete
  #2  
Old December 21st, 2009, 07:34 PM posted to microsoft.public.excel.misc
Jim Thomlinson
external usenet poster
 
Posts: 2,641
Default More MsgBox questions.

Extremely minor point (picky almost beyond reason) but you are better off to
declare ans as

Dim ans As VbMsgBoxResult

--
HTH...

Jim Thomlinson


"Jacob Skaria" wrote:

Try one of these

Sub Macro1()
If MsgBox("Message", 1) vbOK Then Exit Sub
Call subroutine
End Sub


Sub Macro2()
Dim ans As Variant

ans = MsgBox("Message", 1)
If ans = vbOK Then
Call [subroutine]
Else
Exit Sub
End If

End Sub

--
Jacob


"Pete" wrote:

I am attempting to use the Msgbox function with the Ok/Cancel buttons. the
code I have written thus far is below:

Msgbox("Message",1)

If ans = vbOk then call [subroutine]
If ans = vbCancel the exit sub

end if

end sub

The subroutine does not work when the "Ok" button is used. I have tried
other variations on this to no avail. Could anyone please assist?
--

Thanks,
Pete

  #3  
Old December 21st, 2009, 09:24 PM posted to microsoft.public.excel.misc
Dave Peterson
external usenet poster
 
Posts: 19,791
Default More MsgBox questions.

I'd use:

Dim ans as long

If I recall correctly (and I may not bg), this type doesn't exist in earlier
versions of excel (xl2k added it????).

I remember posting a suggestion that used it and the OP had trouble--but that
was a pretty long time ago.

Jim Thomlinson wrote:

Extremely minor point (picky almost beyond reason) but you are better off to
declare ans as

Dim ans As VbMsgBoxResult

--
HTH...

Jim Thomlinson

"Jacob Skaria" wrote:

Try one of these

Sub Macro1()
If MsgBox("Message", 1) vbOK Then Exit Sub
Call subroutine
End Sub


Sub Macro2()
Dim ans As Variant

ans = MsgBox("Message", 1)
If ans = vbOK Then
Call [subroutine]
Else
Exit Sub
End If

End Sub

--
Jacob


"Pete" wrote:

I am attempting to use the Msgbox function with the Ok/Cancel buttons. the
code I have written thus far is below:

Msgbox("Message",1)

If ans = vbOk then call [subroutine]
If ans = vbCancel the exit sub

end if

end sub

The subroutine does not work when the "Ok" button is used. I have tried
other variations on this to no avail. Could anyone please assist?
--

Thanks,
Pete


--

Dave Peterson
 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:33 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.