Good afternoon, I have this code to send a email once the workbook is open but i need to amend it to copy data from a worksheet and send at a certain time of the day, The workbook will stay perm open or could auto open at a certain time using a scheduled task, could someone help me to add it into this code?
Thank you
Private Sub Workbook_Open()
Dim stdocname As String
Dim objmessage As Variant
Dim objconfig As Variant
Dim Recipients As Variant
Dim CC As Variant
Dim BCC As Variant
Dim From As Variant
Dim Subject As Variant
Dim HTMLBody As Variant
Dim Line1, line2 As Variant
Dim html As Variant
Dim response As Variant
Dim ReportName As Variant
Dim ReportNameFile As Variant
Dim mailrec As Variant
Dim chosen As Variant
'********************************************************************************************************************************************************************
' VBMail Starts Here
Set objmessage = CreateObject("CDO.Message")
Set objconfig = CreateObject("CDO.Configuration")
Recipients = "davidjames@1stcreditltd.com" 'Type in your own recipient'
''CC = "" 'Self Explanatory'
''BCC = "" 'Self Explanatory'
From = "GavinFlynn@1stcredit.com" 'No Spaces'
Subject = "Test - " & Format(Now(), "hh:mm") 'This can whatever the message needs to be
HTMLBody = "Your Message" 'This can whatever the message needs to be'
With objconfig.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Do not change'
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "1st-mbx1.local.1stcreditltd.com" 'This needs to the name of your compnay exchange'
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30 'Do not change'
.Update
End With
With objmessage
.Configuration = objconfig
.To = Recipients
.CC = CC
.BCC = BCC
.From = From
.Subject = Subject
.HTMLBody = HTMLBody
.Send
End With
'Destroy Objects
'Set objmessage = Nothing
'Set objconfig = Nothing
' VBMail Ends Here
End Sub
Bookmarks