Thank you for Visiting my Blog

Friday, 14 July 2017

How To use MsgBox in VBA



MsgBox:

 The MsgBox function displays a message box and waits for the user to input and based of user input next operation will be performed.

Syntax:

MsgBox(prompt[,buttons][,title][,helpfile,context])

Below is the few examples of MsgBox :

#1.
 
Sub MsgBX()
''''' declaring variable '''''
Dim A AS STRING
Dim B AS STRING
'''''  Reading data from cell  '''''
A = ThisWorkbook.Worksheets("MsgBX").Cells(3, 2).Value
B = ThisWorkbook.Worksheets("MsgBX").Cells(4, 2).Value
 ''''' Displaying output  '''''
MsgBox (A & " " & B)

End Sub

 

 
#2.
Sub MsgBx1()
'''''' directly strings can be print using double quotes '''''
MsgBox ("Hello World")
End Sub
#3.
Sub MsgBx1()
'''''' directly strings can be print using double quotes '''''
MsgBox ( "Hello" & vbNewLine & "World")
End Sub

 
#4.
Sub MsgBx()
'''''' Below syntax Prompt,buttons,options '''''
A = MsgBox("Do you want to perform this operation", 3, "This is my Title")
'''''' 3 will give 3 buttons Yes, No & Cancel '''''
End Sub

 

No comments:

Post a Comment