INTRODUCTION
Hmmm forgot something? What is it now? Birthdays? I don’t know…. How about events? Occasion? Meetings?……. Oh well I don’t know, I am too busy person, if I have a secretary or assistant that reminds me when there are up coming events, birthdays, meetings, occasion, etc. etc. Do you have one?
Nothing to worry about, because Anna is here, Anna (please see this link to know who/what is Anna) will help you for reminding you what are up coming events even you forgot them all :). Relax and take a break and a have cup of coffee
First before we proceed, setting up your MS Excel
SETTING UP YOUR VBA
Open your workbook (Microsoft Excel File)
Enable your Developer Tab (see here how to Show your Developer Tab on the ribbon)
You have to allow or enable the settings for macro to run the code
(File –> Option –> Trust Center –>Trust Center Settings –> Macro Settings –> Check “Enable all macros”)
HOW TO WORK IT OUT
See first how to run your code at the start up of your workbook
(Simple)
Then write this code;
Private Sub Workbook_Open()
Dim SpeakToMe As Object
Set SpeakToMe = CreateObject(“sapi.spvoice”)
If Date = DateValue(“11/23/2015”) Then
SpeakToMe.Speak (“Would you like to greet your girlfriend sir?, it’s her birthday today!”)
End If
End Sub
Testing your work
Close the code editor
Re-open your workbook (MS Excel File) to test it
Note: Make sure you have speakers or headset, and set it to right volume
MORE! MORE! MORE!
Have you heard her reminders? Absolutely clear as crystal!
But what about other events, like occasions, meetings, discussions with and more?
Well write it down your code:
Private Sub Workbook_Open()
Dim SpeakToMe As Object
Set SpeakToMe = CreateObject(“sapi.spvoice”)
If Date = DateValue(“11/23/2015”) Then
SpeakToMe.Speak (“Would you like to greet your girlfriend sir?, it’s her birthday today!”)
ElseIf Date = DateValue(“11/24/2015”) Then
SpeakToMe.Speak (“Sir you have a meeting today with your clients”)
ElseIf Date = DateValue(“11/25/2015”) Then
SpeakToMe.Speak (“Sir you have a special occasion today with your family”)
ElseIf Date = DateValue(“11/26/2015”) Then
SpeakToMe.Speak (“Sir you have a discussion with your students”)
‘anndd many many more
End If
End Sub
or (for easy to read and easy to decipher)
Using Select Case statement
Private Sub Workbook_Open()
Dim SpeakToMe As Object
Set SpeakToMe = CreateObject(“sapi.spvoice”)
Select Case Date
Case DateValue(“11/23/2015”)
SpeakToMe.Speak (“Would you like to greet your girlfriend sir?, it’s her birthday today!”)
Case DateValue(“11/24/2015”)
SpeakToMe.Speak (“Sir you have a meeting today with your clients”)
Case DateValue(“11/25/2015”)
SpeakToMe.Speak (“Sir you have a special occasion today with your family”)
Case DateValue(“11/26/2015”)
SpeakToMe.Speak (“Sir you have a discussion with your students”)
‘just follow the pattern if you want to add more
End Select
End Sub
ADDITIONAL: Using Notepad
For Visual Basic Script, you can run the “Reminders from Anna” from notepad. Create a text file using notepad, copy and paste this code to blank pad.
Note: I used Select Case statement rather than IF statement.
Set SpeakToMe = CreateObject(“sapi.spvoice”)
Select Case Date
Case DateValue(“11/23/2015”)
SpeakToMe.Speak (“Would you like to greet your girlfriend sir?, it’s her birthday today!”)
Case DateValue(“11/24/2015”)
SpeakToMe.Speak (“Sir you have a meeting today with your clients”)
Case DateValue(“11/25/2015”)
SpeakToMe.Speak (“Sir you have a special occasion today with your family”)
Case DateValue(“11/26/2015”)
SpeakToMe.Speak (“Sir you have a discussion with your students”)
End Select
Run your .vbs file
DOWNLOAD SAMPLE FILE
(if you don’t trust these files, scan first using your anti-virus or anti-malware program)