Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript Tweaking (Send E-mail With Attachment And Include Date)

Status
Not open for further replies.

harryhoudini66

Technical User
Jun 20, 2006
90
US
Hello again,

I have a script that I created (googled it really) that creates an e-mail and attaches a document. I need some help relating to the subject line for the e-mail.

Why? Well there is an e-mail that is sent out four times (6:00am, 11:00am, 3:00pm, 7:00pm) per day that includes an attachment (Thanks again Skip for helping). I plan on using Windows Scheduler to schedule these four events. The reason I want to use a script is that users are constantly forgetting to enter the date or time interval in the subject line.

6:00am Report: This includes prior day information. I need the subject line to show the prior day's date. The script I have listed works for current date only.

11:00am Report: This report contains todays data for the 700am-11:00am interval period. Therefore the subject line has to read “Interval Report [Current Date] 7:00am-11:00am. I am not sure how to add the 7:00am-11:00am text to the subject line.

3:00pm Report: Same request as above except the interval period would be 11:00am-3:00pm. The subject line needs to read "Interval Report [Current Date] 11:00am-3:00pm"

7:00pm Report: Same request as above except the interval period would be 3:00pm-7:00pm
The subject line needs to read "Interval Report [Current Date] 3:00pm-7:00pm"

Thank you all in advance for your help.

Much appreciated.

============
Dim objOutl
Set objOutl = CreateObject("Outlook.Application")
Set objMailItem = objOutl.CreateItem(olMailItem)
'comment the next line if you do not want to see the outlook window
objMailItem.Display
strEmailAddr = "recipient@email.com"
objMailItem.Recipients.Add strEmailAddr
objMailItem.Subject = "Interval Report "& Date
objMailItem.HTMLBody = "My HTML Text Goes Here"
objMailItem.Attachments.Add "\\fileserver2\MSC\MSC_Reports\Interval\MSCInteReportvWindows_7.xlsx"
objMailItem.Display
Set objMailItem = nothing
Set objOutl = nothing
=============
 
Oops, I forgot to mention, not a huge deal but does anyone know how to bypass the Outlook warning letting you know a program is trying to access the e-mail client?
 

hi,

something like this?
Code:
dim sHR as string, sSUB as string, sDAT as string

sHR = format(now, "hh")
sDAT = format(date, "yyyy/mm/dd")

if sHR  > "19" then
   sSUB = "Interval Report " & format(date-1, "yyyy/mm/dd")
elseif sHR  > "15" then
   sSUB = "Interval Report " & sDat & " 3:00pm-7:00pm"
elseif sHR  > "11" then
   sSUB = "Interval Report " & sDat & "11:00am-3:00pm"
elseif sHR  > "06" then
   sSUB = "Interval Report " & sDat & " 7:00am-11:00am"
elseif sHR  > "00" then
   sSUB = "Interval Report " & format(date-1, "yyyy/mm/d")
end if


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks, how would the complete code look? Not sure where to place that snippet. Would it be at the bottom?
 
BTW, I want to thank you again for your help. Based on the information you provided I was able to create four different scripts (one for each of the reports) that contains the right information.

I know my method is kind of Mickey Mouse but it works. I do however like the sample you provide above since it looks like one script could be used for all four reports. I very much prefer to use what you suggested though. Just need to know what the complete code looks like.
 
Also, do you know of a way to supress the Outlook message that displays? The one that says a program is trying to access e-mail? I think I read you have to use the SendKey option. I just dont know how that works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top