Thursday, February 10, 2011

Valentines Day Excel Workbook VBA

Admittedly, this could be made into so much more of an elaborate greeting but then perhaps flowers or chocolates would be more suitable.  

This short script, when placed within the 'This Workbook' section in the project section in your VB browser, will activate any time a change is made to that workbook (i.e. selecting a cell).

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    x = MsgBox("Will you be my valentine?", vbYesNo, "Valentine Greeting")
    If x = 6 Then
        MsgBox "I am yours"
    Else
        MsgBox "Happy Valentines Day!"
    End If
End Sub

As you can see, a pop-up window will appear with the question "Will you be my valentine?"  If the user selects yes you see a new pop-up window with "I am yours".  If no is selected they will only see "Happy Valentines Day!".  Surprise the Excel geek in your life with a workbook today and a custom message of your choosing and have a happy valentine's day!

No comments: