Share via

VBA and good

Martin Lewis 40 Reputation points
2026-02-08T06:33:16.7066667+00:00

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

Developer technologies | Visual Basic for Applications
0 comments No comments

Answer accepted by question author
  1. Q&A Assist
    2026-02-08T06:33:25.3233333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    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:

    1. Open Microsoft Word and enable the Developer tab if you haven't already. You can do this by going to File > Options > Customize Ribbon and checking the Developer option.
    2. Open the Visual Basic for Applications (VBA) Editor by clicking on the Visual Basic button in the Developer tab.
    3. Insert a new module by right-clicking on any of the items in the Project Explorer and selecting Insert > Module.
    4. Copy and paste the following code into the module:
         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
      
    5. Run the macro by pressing F5 or by going back to Word, selecting Macros from the Developer tab, choosing AddGreetings, and clicking Run.

    This macro checks the current time and inserts the appropriate greeting into the document at the current cursor position.


    References:

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.