alundra828
01-29-2016, 06:53 AM
Good afternoon all!
I have a bit of code that essentially sends off an attachment from a given folder, and a subject via a secure email account. Which is fine and dandy, it all works no problems at all. But I want to be able to have this macro run at a certain point of the day on weekdays only.
Preferably 9:30am mon - fri. I'm completely drawing a blank on how it can be done, can any of you help? Thanks in advance!
My code is below
Option Explicit
Sub SendTEC()
Const strPath As String = "NETWORK PATH"
Dim strChar As String
Dim strFile As String
strFile = Dir$(strPath & "*.*") 'any file in the folder
While strFile <> ""
CreateMessage strPath & strFile, Mid(strFile, 2, 2)
DoEvents
strFile = Dir$()
Wend
Exit Sub
End Sub
Sub CreateMessage(strAtt As String, strChar As String)
Dim oAccount As Account
Dim olMail As MailItem
Dim olAttach As Attachment
Const strAcc = "EMAIL" 'the name of the account to use
For Each oAccount In Application.Session.Accounts
If oAccount.DisplayName = strAcc Then
Set olMail = Outlook.CreateItem(olMailItem)
With olMail
.SendUsingAccount = oAccount
.To = "DESTINATION EMAIL"
.Subject = strChar
.Body = "" ' clear the body
Set olAttach = .Attachments.Add(strAtt)
'.Display
.Send '- Restore after testing
End With
Exit For
End If
Next
lbl_Exit:
Set olMail = Nothing
Set olAttach = Nothing
Set oAccount = Nothing
Exit Sub
End Sub
I have a bit of code that essentially sends off an attachment from a given folder, and a subject via a secure email account. Which is fine and dandy, it all works no problems at all. But I want to be able to have this macro run at a certain point of the day on weekdays only.
Preferably 9:30am mon - fri. I'm completely drawing a blank on how it can be done, can any of you help? Thanks in advance!
My code is below
Option Explicit
Sub SendTEC()
Const strPath As String = "NETWORK PATH"
Dim strChar As String
Dim strFile As String
strFile = Dir$(strPath & "*.*") 'any file in the folder
While strFile <> ""
CreateMessage strPath & strFile, Mid(strFile, 2, 2)
DoEvents
strFile = Dir$()
Wend
Exit Sub
End Sub
Sub CreateMessage(strAtt As String, strChar As String)
Dim oAccount As Account
Dim olMail As MailItem
Dim olAttach As Attachment
Const strAcc = "EMAIL" 'the name of the account to use
For Each oAccount In Application.Session.Accounts
If oAccount.DisplayName = strAcc Then
Set olMail = Outlook.CreateItem(olMailItem)
With olMail
.SendUsingAccount = oAccount
.To = "DESTINATION EMAIL"
.Subject = strChar
.Body = "" ' clear the body
Set olAttach = .Attachments.Add(strAtt)
'.Display
.Send '- Restore after testing
End With
Exit For
End If
Next
lbl_Exit:
Set olMail = Nothing
Set olAttach = Nothing
Set oAccount = Nothing
Exit Sub
End Sub