[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Need help with VBScript

Posted on 2016-09-03
6
Medium Priority
?
22 Views
Last Modified: 2016-09-28
Have the following script but I'm struggling to get the file  Pcomb Error Report.
The file, for example, is saved as  Pcomb Error Report DDMMYY and is emailed the following morning.

Dim myDateString, myStart, myMessage, myDatestring2, myattachment

myDateString = DateAdd("d", -1, Date)

strDatestring1 = Replace(mydatestring,"/","")
strdatestring2 = Mid(strDatestring1,1,4)
strdatestring3 = Mid(strDatestring1,7)

strDayofMonth1 = Datepart("d",mydatestring)
strMonth1 = Datepart("m",mydatestring)
strYear1 = Datepart("yyyy",mydatestring)

strDayOfMonth = right("0" & day(date()),2) - 1
strMonth = right("0" & month(date()),2)
strYear = right (year(date()),2)


mydatestring2 = strDayOfMonth & strMonth & strYear

myattachment = "N:\Users\Production\ops\Ops Documents\PCOMB Errors\TCQ Pcomb Error Report " & strdatestring2 & strdatestring3 &".doc"
myMessage = "PCOMB Timings & Error Report " & myDateString 
Set outlookApp = CreateObject("Outlook.Application")

olMailItem = 0
Set newMessage = outlookApp.CreateItem(olMailItem)

newMessage.To = "test@hotmail.com"
newMessage.Subject = myMessage
newMessage.Attachments.Add "N:\Users\Production\ops\Ops Documents\Spreadsheets and templates\PCOMB_Timings.xls"
newMessage.Attachments.Add "N:\Users\Production\ops\Ops Documents\PCOMB Errors\Pcomb Error Report " & strdatestring2 & strdatestring3 &".doc"
newMessage.Subject = myMessage

newMessage.Display

Open in new window

0
Comment
Question by:Ferhat Er
  • 3
  • 2
5 Comments
 
LVL 59

Expert Comment

by:Bill Prew
ID: 41783313
Give this a try.

Dim datYesterday, strDDMMYY, myStart, myMessage, myattachment

datYesterday = DateAdd("d", -1, Now())
strDDMMYY = Right("0" & Day(datYesterday), 2) & Right("0" & Month(datYesterday), 2) & Right(Year(datYesterday), 2)

myattachment = "N:\Users\Production\ops\Ops Documents\PCOMB Errors\TCQ Pcomb Error Report " & strDDMMYY &".doc"
myMessage = "PCOMB Timings & Error Report " & strDDMMYY

Set outlookApp = CreateObject("Outlook.Application")

olMailItem = 0
Set newMessage = outlookApp.CreateItem(olMailItem)

newMessage.To = "test@hotmail.com"
newMessage.Subject = myMessage
newMessage.Attachments.Add "N:\Users\Production\ops\Ops Documents\Spreadsheets and templates\PCOMB_Timings.xls"
newMessage.Attachments.Add "N:\Users\Production\ops\Ops Documents\PCOMB Errors\Pcomb Error Report " & strDDMMYY &".doc"
newMessage.Subject = myMessage

newMessage.Display

Open in new window

~bp
1
 

Author Comment

by:Ferhat Er
ID: 41783563
Much appreciated Bill.
This works perfectly.
Another question. When I launch this script it opens it in outlook with my signature, but i also would like to add to the body the following:

Good Morning,

Please find attached the PCOMB Timings and Error Report for DD/MM/YY. (<- This date would be previous days date like the file attachment)

Can you assist with this as well pretty please?

Best Regards,
Ferhat
0
 
LVL 59

Accepted Solution

by:
Bill Prew earned 2000 total points (awarded by participants)
ID: 41784127
Give this a try.

Dim datYesterday, strDDMMYY, myStart, myMessage, myattachment, strEmail

datYesterday = DateAdd("d", -1, Now())
strDDMMYY = Right("0" & Day(datYesterday), 2) & Right("0" & Month(datYesterday), 2) & Right(Year(datYesterday), 2)
strEmail = Right("0" & Day(datYesterday), 2) & "/" & Right("0" & Month(datYesterday), 2) & "/" & Right(Year(datYesterday), 2)

myattachment = "N:\Users\Production\ops\Ops Documents\PCOMB Errors\TCQ Pcomb Error Report " & strDDMMYY &".doc"
myMessage = "PCOMB Timings & Error Report " & strDDMMYY

Set outlookApp = CreateObject("Outlook.Application")

olMailItem = 0
Set newMessage = outlookApp.CreateItem(olMailItem)

newMessage.To = "test@hotmail.com"
newMessage.Subject = myMessage
newMessage.Attachments.Add "N:\Users\Production\ops\Ops Documents\Spreadsheets and templates\PCOMB_Timings.xls"
newMessage.Attachments.Add "N:\Users\Production\ops\Ops Documents\PCOMB Errors\Pcomb Error Report " & strDDMMYY &".doc"
newMessage.Body = "Good Morning," & vbCrLf & vbCrLf & "Please find attached the PCOMB Timings and Error Report for " & strEmail & "." & vbCrLf

newMessage.Display

Open in new window

~bp
1
 

Author Comment

by:Ferhat Er
ID: 41787008
Thank you Bill. That has worked. Much appreciated.
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 41787053
Welcome.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month19 days, 21 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question