How do I build a MSGBOX

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,907
Office Version
  1. 365
Platform
  1. Windows
Hi,

I know the basics of msgbox, but I want to add a yes/no button. I have the following code:
Code:
Private Sub Workbook_Open()
If AddIns("Analysis Toolpak").Installed = False Then
MsgBox ("This model cannot function without Analysis Toolpak installed.  Excel will now install Analysis Toolpak.  Call IT Help Desk if this fails to install properly.")
AddIns("Analysis Toolpak").Installed = True
Calculate
End If
End Sub

I would like to give the user the option to install it (Yes/No in msgbox).

Thanks,
Noj :biggrin:
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Oh, and how do I break the code across several lines? I have to scroll to right constantly when I read the code, is there a way that I can continue on the line below without upsetting it?
 
Upvote 0
Code:
MsgBox  prompt :="This model cannot function without Analysis Toolpak installed.  Excel will now install Analysis Toolpak.  Call IT Help Desk if this fails to install properly.", buttons := vbyesno

you can find that literally in the excel help btw ;)

Second part I don't know. Think that is impossible :eek:
 
Upvote 0
Ok, but I'm an idiot. This doesn't stop the addin from being installed when I click no.
:unsure:
 
Upvote 0
Oh, and how do I break the code across several lines? I have to scroll to right constantly when I read the code, is there a way that I can continue on the line below without upsetting it?

[space]_
This will connect the first line with the second
Spacebar and underscore.
 
Upvote 0
noj,

Does this help you out?
<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Workbook_Open()
<SPAN style="color:#00007F">Dim</SPAN> i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Byte</SPAN>
    <SPAN style="color:#00007F">If</SPAN> AddIns("Analysis Toolpak").Installed = <SPAN style="color:#00007F">False</SPAN> <SPAN style="color:#00007F">Then</SPAN>
        i = MsgBox("This model cannot function without Analysis Toolpak installed." _
            & vbLf & "Excel will now install Analysis Toolpak." _
            & vbLf & "Call IT Help Desk if this fails to install properly." _
            & vbLf & vbLf & "Do you want to install Analysis Toolpak?", vbYesNo)
        <SPAN style="color:#00007F">If</SPAN> i = vbYes <SPAN style="color:#00007F">Then</SPAN>
            AddIns("Analysis Toolpak").Installed = <SPAN style="color:#00007F">True</SPAN>
            Calculate
        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
 
Upvote 0
Here is a MsgBox shell you can use:

Sub BButton()
'Run from sheet module, like: Sheet1.
Dim Msg, Style, Title, Help, Ctxt, Response, MyString

On Error GoTo myErr

Msg = "Do you want to continue ?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "MsgBox Demonstration" ' Define title.
Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic context.

'Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.

MyString = "Yes" ' Perform some action.

MsgBox (MyString)

Else ' User chose No.

MyString = "No" ' Perform some action.

MsgBox (MyString)
GoTo MyEnd

myErr:
'Error message!
MsgBox "An InPut or Reference error has occured!"

MyEnd:
End If
End Sub


P.S: You break code up by inserting: "A space then an underline, then a carrage return!"

Like:

myMessage = "To enter your responce to: " & vbCr & vbCr & _
theAnswer & vbCr & vbCr & " Please only use spaces as your only" & _
" formmating!"
 
Upvote 0

Forum statistics

Threads
1,215,330
Messages
6,124,305
Members
449,150
Latest member
NyDarR

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
Back
Top