Please could someone help. I am trying to get a message box to give an A or
B option. In otherwords if you choose A it would save into Town or B into
Country. I only know how to get a Yes No situation. Could anyone help
please. I have put the example of what I am trying to get to work below.

Margaret

Dim intMsgBoxResult As Integer
intMsgBoxResult = MsgBox("Town or Country", vbYesNo + _
vbQuestion, "Current Status")
If intMsgBoxResult = vbYes Then

With Dialogs(wdDialogFileSaveAs)
.Name = "C:\My Documents\Town Details 2003\"
.Show
End With

Else

With Dialogs(wdDialogFileSaveAs)
.Name = "C:\My Documents\Country Details 2003\"
.Show

End With

End If

Re: Message Boxes by Jay

Jay
Tue Dec 09 21:02:36 CST 2003

Hi, Margaret,

As you've already found out, the MsgBox feature allows only a few
varieties of buttons and doesn't let you change the text on the
buttons.

But you can make a userform (custom dialog) look like a message box,
and there you can create whatever buttons and labels you like.

For this, make a small userform (in the VBA editor, click Insert >
Userform, and drag the edges to message-box size). In the Properties
panel, rename the userform as frmTownCountry, and put Current Status
in the Caption box.

From the toolbox, add two command buttons and size them down a bit.
Give one of them the name btnTown, caption it Town, and give it the
accelerator t (that puts the underline under the T in the caption, and
lets the user use Alt+T as a shortcut). For the other button, name it
btnCountry, caption Country, accelerator c.

Press F7 (or View > Code) to go to the userform's code window, and
paste in this code:

Public Result As String

Private Sub btnCountry_Click()
Result = "Country"
Me.Hide
End Sub

Private Sub btnTown_Click()
Result = "Town"
Me.Hide
End Sub

Private Sub UserForm_Initialize()
Result = ""
End Sub

This says that when the user clicks the Town button, the variable
Result will get the string "Town" and the userform will disappear;
similarly for a click on the Country button. If the user clicks the X
in the title bar, the Result string will be empty.

Now edit your macro to this:

Dim myMsgBox As frmTownCountry
Set myMsgBox = New frmTownCountry
myMsgBox.Show

If myMsgBox.Result = "" Then ' canceled
Exit Sub
End If

If myMsgBox.Result = "Town" Then
With Dialogs(wdDialogFileSaveAs)
.Name = "C:\My Documents\Town Details 2003\"
.Show
End With
Else
With Dialogs(wdDialogFileSaveAs)
.Name = "C:\My Documents\Country Details 2003\"
.Show
End With
End If

Set myMsgBox = Nothing

This shows the userform instead of the original message box, and uses
the Result variable to decide what to show.

"Margaret Upton" <margaretupton@btinternet.com> wrote:

>Please could someone help. I am trying to get a message box to give an A or
>B option. In otherwords if you choose A it would save into Town or B into
>Country. I only know how to get a Yes No situation. Could anyone help
>please. I have put the example of what I am trying to get to work below.
>
>Margaret
>
>Dim intMsgBoxResult As Integer
>intMsgBoxResult = MsgBox("Town or Country", vbYesNo + _
> vbQuestion, "Current Status")
>If intMsgBoxResult = vbYes Then
>
>With Dialogs(wdDialogFileSaveAs)
> .Name = "C:\My Documents\Town Details 2003\"
> .Show
>End With
>
>Else
>
>With Dialogs(wdDialogFileSaveAs)
> .Name = "C:\My Documents\Country Details 2003\"
> .Show
>
>End With
>
>End If
>
>
>
>


--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://www.mvps.org/word

Re: Message Boxes by Margaret

Margaret
Wed Dec 10 10:02:53 CST 2003

Hi Jay

Thank you very much for your help, I am most grateful.

Margaret

"Jay Freedman" <jay.freedman@verizon.net> wrote in message
news:ef2dtv89cq2781lit7tc5snvd3179r6s6m@4ax.com...
> Hi, Margaret,
>
> As you've already found out, the MsgBox feature allows only a few
> varieties of buttons and doesn't let you change the text on the
> buttons.
>
> But you can make a userform (custom dialog) look like a message box,
> and there you can create whatever buttons and labels you like.
>
> For this, make a small userform (in the VBA editor, click Insert >
> Userform, and drag the edges to message-box size). In the Properties
> panel, rename the userform as frmTownCountry, and put Current Status
> in the Caption box.
>
> From the toolbox, add two command buttons and size them down a bit.
> Give one of them the name btnTown, caption it Town, and give it the
> accelerator t (that puts the underline under the T in the caption, and
> lets the user use Alt+T as a shortcut). For the other button, name it
> btnCountry, caption Country, accelerator c.
>
> Press F7 (or View > Code) to go to the userform's code window, and
> paste in this code:
>
> Public Result As String
>
> Private Sub btnCountry_Click()
> Result = "Country"
> Me.Hide
> End Sub
>
> Private Sub btnTown_Click()
> Result = "Town"
> Me.Hide
> End Sub
>
> Private Sub UserForm_Initialize()
> Result = ""
> End Sub
>
> This says that when the user clicks the Town button, the variable
> Result will get the string "Town" and the userform will disappear;
> similarly for a click on the Country button. If the user clicks the X
> in the title bar, the Result string will be empty.
>
> Now edit your macro to this:
>
> Dim myMsgBox As frmTownCountry
> Set myMsgBox = New frmTownCountry
> myMsgBox.Show
>
> If myMsgBox.Result = "" Then ' canceled
> Exit Sub
> End If
>
> If myMsgBox.Result = "Town" Then
> With Dialogs(wdDialogFileSaveAs)
> .Name = "C:\My Documents\Town Details 2003\"
> .Show
> End With
> Else
> With Dialogs(wdDialogFileSaveAs)
> .Name = "C:\My Documents\Country Details 2003\"
> .Show
> End With
> End If
>
> Set myMsgBox = Nothing
>
> This shows the userform instead of the original message box, and uses
> the Result variable to decide what to show.
>
> "Margaret Upton" <margaretupton@btinternet.com> wrote:
>
> >Please could someone help. I am trying to get a message box to give an A
or
> >B option. In otherwords if you choose A it would save into Town or B into
> >Country. I only know how to get a Yes No situation. Could anyone help
> >please. I have put the example of what I am trying to get to work below.
> >
> >Margaret
> >
> >Dim intMsgBoxResult As Integer
> >intMsgBoxResult = MsgBox("Town or Country", vbYesNo + _
> > vbQuestion, "Current Status")
> >If intMsgBoxResult = vbYes Then
> >
> >With Dialogs(wdDialogFileSaveAs)
> > .Name = "C:\My Documents\Town Details 2003\"
> > .Show
> >End With
> >
> >Else
> >
> >With Dialogs(wdDialogFileSaveAs)
> > .Name = "C:\My Documents\Country Details 2003\"
> > .Show
> >
> >End With
> >
> >End If
> >
> >
> >
> >
>
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://www.mvps.org/word