Developer technologies | Visual Basic for Applications
An implementation of Visual Basic that is built into Microsoft products.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
VBA Cde to add good morning afternoon and evening into word How to set up in full
Mod moved from : Windows for home | Windows 11 | Settings
An implementation of Visual Basic that is built into Microsoft products.
Answer accepted by question author
To add greetings like "Good Morning", "Good Afternoon", and "Good Evening" into a Word document using VBA, you can create a simple macro. Here’s how you can set it up:
Sub AddGreetings()
Dim currentTime As Date
currentTime = Now
If Hour(currentTime) < 12 Then
Selection.TypeText "Good Morning"
ElseIf Hour(currentTime) < 17 Then
Selection.TypeText "Good Afternoon"
Else
Selection.TypeText "Good Evening"
End If
End Sub
AddGreetings, and clicking Run.This macro checks the current time and inserts the appropriate greeting into the document at the current cursor position.
References: