Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default More MsgBox questions.

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Answers to questions posing more questions in a workbook sbelle1 Excel Worksheet Functions 2 August 8th 09 01:02 AM
View Questions and Answer to questions I created Roibn Taylor Excel Discussion (Misc queries) 4 July 24th 08 12:05 AM
msgbox peyman Excel Discussion (Misc queries) 5 October 4th 07 09:56 PM
MsgBox bumper338 Excel Discussion (Misc queries) 1 December 22nd 06 11:32 PM
msgbox James Coughlan Excel Discussion (Misc queries) 3 May 3rd 06 01:57 PM


All times are GMT +1. The time now is 12:24 PM.

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

About Us

"It's about Microsoft Excel"