Good morning, I hope you're all well today.
I've been trying to find a solution, and various threads I check are all related to running VBA at specific times and intervals.
What I'm after is the following:
If the current time is AM, when I press the button the macro is assigned to, run the following code:
If the current time is PM, when I press the button the macro is assigned to, run the following code:
All help is greatly appreciated.
Thank you.
Regards.
Marhier.
I've been trying to find a solution, and various threads I check are all related to running VBA at specific times and intervals.
What I'm after is the following:
If the current time is AM, when I press the button the macro is assigned to, run the following code:
VBA Code:
Sub OrderEmail()
If MsgBox("Have you selected a cell from the line of the schedule you'd like to order?", vbYesNo) = vbNo Then Exit Sub
Application.ScreenUpdating = False
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim sRng As Range
Set wsSheet = ActiveSheet
Set sRng = wsSheet.Range("Z3")
Set ProjectManagerEmail = wsSheet.Range("P4")
Set ProjectManagerEmail2 = wsSheet.Range("P5")
Set Sep = wsSheet.Range("AA1")
Call UnProtect
ActiveSheet.Cells(ActiveCell.Row, 15).Select
Range("Y3").Value = ActiveCell
ActiveSheet.Cells(ActiveCell.Row, 13).Select
Range("Y4").Value = ActiveCell
ActiveSheet.Cells(ActiveCell.Row, 7).Select
Range("Y5").Value = ActiveCell
Call Protect
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Good morning. <br>" & _
"Please deliver as per the attached schedule(s)<br>" & _
"Invoice to RR Ltd.<br><br>" & _
"When responding to this email, or sending an acknowledgement, can you please reply to this email, keeping the subject?<br><br>" & _
"Much appreciated.<br>" & _
"Thank you."
On Error Resume Next
With OutMail
.Display
.To = ""
.CC = ProjectManagerEmail & Sep & ProjectManagerEmail2
.BCC = ""
.Subject = sRng
.HTMLBody = strbody & .HTMLBody
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Application.ScreenUpdating = True
Exit Sub
End Sub
If the current time is PM, when I press the button the macro is assigned to, run the following code:
VBA Code:
Sub OrderEmail()
If MsgBox("Have you selected a cell from the line of the schedule you'd like to order?", vbYesNo) = vbNo Then Exit Sub
Application.ScreenUpdating = False
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim sRng As Range
Set wsSheet = ActiveSheet
Set sRng = wsSheet.Range("Z3")
Set ProjectManagerEmail = wsSheet.Range("P4")
Set ProjectManagerEmail2 = wsSheet.Range("P5")
Set Sep = wsSheet.Range("AA1")
Call UnProtect
ActiveSheet.Cells(ActiveCell.Row, 15).Select
Range("Y3").Value = ActiveCell
ActiveSheet.Cells(ActiveCell.Row, 13).Select
Range("Y4").Value = ActiveCell
ActiveSheet.Cells(ActiveCell.Row, 7).Select
Range("Y5").Value = ActiveCell
Call Protect
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Good afternoon.<br>" & _
"Please deliver as per the attached schedule(s)<br>" & _
"Invoice to RR Ltd.<br><br>" & _
"When responding to this email, or sending an acknowledgement, can you please reply to this email, keeping the subject?<br><br>" & _
"Much appreciated.<br>" & _
"Thank you."
On Error Resume Next
With OutMail
.Display
.To = ""
.CC = ProjectManagerEmail & Sep & ProjectManagerEmail2
.BCC = ""
.Subject = sRng
.HTMLBody = strbody & .HTMLBody
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Application.ScreenUpdating = True
Exit Sub
End Sub
All help is greatly appreciated.
Thank you.
Regards.
Marhier.