Run code if day of month is prior to specific day

rjmdc

Well-known Member
Joined
Apr 29, 2020
Messages
749
Office Version
  1. 365
Platform
  1. Windows
I want to add code that says Call Send Messages if the day of the month is <=23
this way i can add that peice of code to my main process only if it the 23rd or before
 
Pretty straightforward, something like this:
VBA Code:
    If Day(Date) <= 23 Then
        MsgBox "Call Send Messages"
        'Call your code here
    End If
 
Upvote 0
i got stuck
the code to run contains the following:
I dont want the ui interface when its part of the main large process
how do I disregard the ui interface when its part of thelarger process and not on its own?

Rich (BB code):
Sub SendExpirationEmails()
    Dim RptPeriod           As Date:                RptPeriod = Application.WorksheetFunction.EoMonth(wsControl.Range("LastRptPeriod"), 0)
    Dim tbl                 As ListObject:    
'UI Confirm
    If MsgBox("Have you switched to Expense Reports Email Account?", vbYesNo, "Confirm Emails") = vbNo Then
        MsgBox "Process Aborted."
        Exit Sub
    End If
    
    If MsgBox("This process will send emails to all expiring budgets.  Are you sure you want to continue?", vbYesNo, "Confirm Emails") = vbNo Then
        MsgBox "Process Aborted."
        Exit Sub
    End If
 
Upvote 0
Try adding an input parameter to your SendExpirationEmails like this:
VBA Code:
Sub SendExpirationEmails(UI_Confirm As Boolean)
    Dim RptPeriod           As Date:                RptPeriod = Application.WorksheetFunction.EoMonth(wsControl.Range("LastRptPeriod"), 0)
    Dim tbl                 As ListObject:

'UI Confirm
    If UI_Confirm = True Then
        
        If MsgBox("Have you switched to Expense Reports Email Account?", vbYesNo, "Confirm Emails") = vbNo Then
            MsgBox "Process Aborted."
            Exit Sub
        End If
    
        If MsgBox("This process will send emails to all expiring budgets.  Are you sure you want to continue?", vbYesNo, "Confirm Emails") = vbNo Then
            MsgBox "Process Aborted."
            Exit Sub
        End If
    
    End If

Then have your other code pass it a value of FALSE to skip that portion when called from your code like that, i.e.
VBA Code:
    If Day(Date) <= 23 Then
        Call SendExpirationEmails(False)
    End If
 
Upvote 0
I bumped into another error
since I have another sub it says argument not optional

Rich (BB code):
Sub SendAllExpirationEmails()
    Call SendExpirationEmails
End Sub
 
Upvote 0
You will need to add that argument now to every call of that procedure in your code, as you need to tell it whether or not to ask those questions.
If you want it to ask those questions, just use True, i.e.
VBA Code:
    Call SendExpirationEmails(True)
 
Upvote 0
hi
thank you happy new year
no more debugs
I will try to run the beginnng of January to see if it calls the emails
I will report back
 
Upvote 0
hi sorry another debg
process finishes with
Rich (BB code):
MsgBox "Process Complete", vbInformation, "Email Process Complete"

this then needs an ok to proceed
how do i take that away so no messages or input if i run as part of the main process?
 
Upvote 0
Wrap that in another IF statement, like I showed you above with the original code, i.e.
VBA Code:
    If UI_Confirm = True Then
        MsgBox "Process Complete", vbInformation, "Email Process Complete"
    End If
 
Upvote 0

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