+ Reply to Thread
Results 1 to 4 of 4

When you open the workbook and show a greeting message.

Hybrid View

  1. #1
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    When you open the workbook and show a greeting message.

    Hi.
    As I do when I open the workbook and show a message of greeting.

    example from 00:00 to 11:59 show "Good Day"

    in the case of the 12:00 to 17:59 show "Good afternoon"

    in the case of 18:00 to 23:59 show "Good night"
    Private Sub Workbook_Open()
    Dim T As Date
    
    T = Now
    
    If T >= "0:00" Then
    MsgBox "Good Morning"
    
    ElseIf T >= "12:00" Then
    MsgBox "Good afternoon"
    
    ElseIf T >= "18:00" Then
    MsgBox "Good night"
    
    End If
    End Sub
    "No xadrez nem sempre a menor dist?ncia entre dois pontos ? uma linha reta" G. Kasparov.

    If your problem is solved, please say so clearly, and mark your thread as Solved: Click the Edit button on your first post in the thread, Click Go Advanced, select b from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Edit button will not appear -- ask a moderator to mark it.

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: When you open the workbook and show a greeting message.

    If TimeValue(T) < .5 Then
    MsgBox "Good Morning"
    
    ElseIf TimeValue(t) < .75 then
    MsgBox "Good Afternoon"
    Else
    Msgbox "Good night"
    End if
    Times in Excel are a decimal number less then 1; 6:00AM is 0.25, MidDay is 0.5 and 6:00pm 0.75...

  3. #3
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: When you open the workbook and show a greeting message.

    Hi

    Try this:

    Private Sub Workbook_Open()
        Dim T As Date
        
        T = TimeValue(Now)
        
        If T >= "0:00" And T <= "11:59" Then
            MsgBox "Good Morning"
        ElseIf T >= "12:00" And T <= "17:59" Then
            MsgBox "Good afternoon"
        ElseIf T >= "18:00" Then
            MsgBox "Good night"
        End If
    End Sub
    Click *, if my suggestion helps you. Have a good day!!

  4. #4
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Re: When you open the workbook and show a greeting message.

    Hi.
    both answers were great
    Very good!!!

    Thank you!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1