Consulting

Results 1 to 7 of 7

Thread: Solved: Msg Box on 1st of every month

  1. #1
    VBAX Contributor
    Joined
    Jul 2011
    Location
    Manchester
    Posts
    142
    Location

    Solved: Msg Box on 1st of every month

    I need a spreadsheet to automatically pop up a message box on the 1st every month, or first day it is opened after the first of the month.

    I tried using = Now() on one cell e.g. A1 then list 1st of month in range e.g. B1:b60 and trying to match it but cant get it to work.

    Can anyone help please

  2. #2
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    269
    Location
    Mykal66,
    Interesting problem... I would solve it by using the built in document properties for last save time in the workbook_open call. I would save the last time the message was recorded in a cell (can be on a hidden sheet etc) and update that every time the message was given, and on open of the workbook, I would save the workbook.

    That looks like this:
    Of course you will have to change sheet1.cells(1,1) to whatever sheet and cell you want to save it to...
    [VBA]
    Private Sub Workbook_Open()
    Dim savDt As Date
    Dim msgDt As Date

    savDt = ThisWorkbook.BuiltinDocumentProperties("Last Save Time")
    msgDt = Sheet1.Cells(1, 1)

    If Year(msgDt) < Year(savDt) Or Month(msgDt) < Month(savDt) Then
    MsgBox ("You have not seen this message yet this month")
    Sheet1.Cells(1, 1) = Now
    End If

    ThisWorkbook.Save
    End Sub

    [/VBA]

  3. #3
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location

    Thumbs up

    Quote Originally Posted by mykal66
    I need a spreadsheet to automatically pop up a message box on the 1st every month, or first day it is opened after the first of the month.

    I tried using = Now() on one cell e.g. A1 then list 1st of month in range e.g. B1:b60 and trying to match it but cant get it to work.

    Can anyone help please
    You could try putting this in your ThisWorkbook module:

    [VBA]

    Private Sub Workbook_Open()

    If Day(Date) = 1 Then

    MsgBox "Your text here"

    End If

    End Sub

    [/VBA]

  4. #4
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    269
    Location
    You could try putting this in your ThisWorkbook module:

    VBA:
    Private Sub Workbook_Open() If Day(Date) = 1 Then MsgBox "Your text here" End If End Sub
    That would only work for when the workbook was opened on day 1 of the month... if it was day 2 and the first time opened, it would not trigger...

  5. #5
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location
    Quote Originally Posted by CodeNinja
    That would only work for when the workbook was opened on day 1 of the month... if it was day 2 and the first time opened, it would not trigger...
    True, I misread the OP.

  6. #6
    VBAX Contributor
    Joined
    Jul 2011
    Location
    Manchester
    Posts
    142
    Location
    Quote Originally Posted by CodeNinja
    Mykal66,
    Interesting problem... I would solve it by using the built in document properties for last save time in the workbook_open call. I would save the last time the message was recorded in a cell (can be on a hidden sheet etc) and update that every time the message was given, and on open of the workbook, I would save the workbook.

    That looks like this:
    Of course you will have to change sheet1.cells(1,1) to whatever sheet and cell you want to save it to...
    [VBA]
    Private Sub Workbook_Open()
    Dim savDt As Date
    Dim msgDt As Date

    savDt = ThisWorkbook.BuiltinDocumentProperties("Last Save Time")
    msgDt = Sheet1.Cells(1, 1)

    If Year(msgDt) < Year(savDt) Or Month(msgDt) < Month(savDt) Then
    MsgBox ("You have not seen this message yet this month")
    Sheet1.Cells(1, 1) = Now
    End If

    ThisWorkbook.Save
    End Sub

    [/VBA]
    Thank you very much, this seems to work fine- Really appreciated

  7. #7
    VBAX Contributor
    Joined
    Jul 2011
    Location
    Manchester
    Posts
    142
    Location
    Quote Originally Posted by Opv
    You could try putting this in your ThisWorkbook module:

    [VBA]

    Private Sub Workbook_Open()

    If Day(Date) = 1 Then

    MsgBox "Your text here"

    End If

    End Sub

    [/VBA]
    Thank you for trying to help anyway

Posting Permissions

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