10-08-2004, 03:12 PM
Is there a way to put a variable in the first part of this statement:
Answer = MsgBox("Would you like to Print Preview this range?", vbQuestion + vbYesNo, "Confirm Preview")
I would like to be able to have an output of:
Would you like to Print Preview this range(1)?
Any help would be appreciated. Thanks. :D
10-08-2004, 03:17 PM
You can concatenate the value into the string.
' I use a string variable but it's not necessary.
Dim strMessage As String
' Here I use varRangeValue as a place holder for what ever value you want to
' concatenate into the string.
strMessage = "Would you like to Print Preview this " & varRangeValue & " Range?"
' Also note that I use a bitwise OR operation to combine the enumerator values for the
' Buttons argument of the MsgBox function.
Answer = MsgBox(strMessage, vbQuestion Or vbYesNo, "Confirm Preview")
Maybe I should clarify the note about the bitwise OR operation.
Let's say for argument sake that you made a boo-boo and entered in the values for the Buttons argument as:
vbQuestion + vbYesNo + vbYesNo
This would infact assign a value of 40 to the Buttons argument.
Whereas, if you use the bitwise OR operation and made the same boo-boo:
vbQuestion Or vbYesNo Or vbYesNo
This would assign the correct value of 36 to the Buttons argument.
This is because the Or statement used here is actually setting the bits that will make up the value passed and not adding all of the numbers together and then passing the resulting value.