Auto open msgbox depending on date and day

darro

Board Regular
Joined
Mar 10, 2009
Messages
208
i have this code

[/CODE]Private Sub Auto_Open ()
If Day(Now)= 1 Then MsgBox "my text"
End Sub
Code:
How can I make this work on first day of month but if that falls on a weekend then open on next following monday? 

Any ideas very welcome

Cheers.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi, will you be opening the workbook everyday?
If not and you just want msgbox to pop up when your OS starts, you will need to look into a different solution other than VBA.

Anyways,
in Thisworkbook module
Code:
Private Sub ThisWorkbook_Open()
    If Day(Now) = 1 Then
        If Worksheetfunction.Networkdays(Now, Now) = 1 Then
            MsgBox "my text"
        End If
    End If
End Sub

Not too sure about opening on next following monday. I suspect you will need to allocate a cell of the workbook for displaying TRUE/FALSE for the status of the 'following monday'
 
Upvote 0
Hi thanks for the reply. I will be using the book everyday except the weekend. The code I posted does work for 1st of the month but still dont know how to make it work if the 1st is a Sat or Sun and I open it the following Monday.

Any more ideas?
 
Upvote 0
Any ideas out there? How cab I make this pop up on the
first of month. But if The first is a sat or sun, it waits and pops up on the following monday? Is it even possible?

Cheers
 
Upvote 0
Hi, darro..
Try this code as I have suggested before (you will need to allocate not used cell for this)

Code:
Private Sub ThisWorkbook_Open()
    If Worksheets("Sheet1").Range("A1").Value = "" Then
        Worksheets("Sheet1").Range("A1").Value = Now
    If Month(Worksheets("Sheet1").Range("A1").Value) < Month(Now) Then
        MsgBox "my text"
        Worksheets("Sheet1").Range("A1").Value = Now
    End If
End Sub

This will require cell A1 of Sheet1 and that you open it every single day (excluding the weekends)
 
Upvote 0
I have the code I posted above that will pop up a msgbox. I've put that in a general module. In Auto_open I am trying to write a code to check a named range called ARCD to see if it contains the date 1st of current month. If not it exits sub. If so it calls the pop up code.

I can get it to call the other code but it ignores whatever is in ARCD.

How I get the code to check the range and exit and NOT run the pop up macro if the date is found?

Thanks for all your help.
 
Upvote 0
Hi, you can check a named range by
Code:
If Worksheets("Sheet1").Range("ARCD").Value = 1 Then
    Exit Sub 'exiting the whole procedure
End If

As per to your pop up macro question,
you can simply take out MsgBox line to not run the pop up macro..
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top