Issue with scheduled macro - running more than once

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
jonesey10
Newbie
Posts: 8
Joined: Wed Mar 31, 2010 3:11 pm

Issue with scheduled macro - running more than once

Post by jonesey10 » Thu Jul 19, 2012 12:34 pm

I have a script that reads a text file and sends out an email. In the last week, the email sent out 15-20 times when it should only be sent out once. It doesn't happen every day.

I'm currently running macro schedule 11.1.23 and was recently upgraded to windows 7, so I'm not sure if that is the issue. The script is below. Any help would be greatly appreciated.

VBStart

Function CreateEmail(strRecipient, strSubject, strBody)
'Create OL App object
Set objOLApp = CreateObject("Outlook.Application")

If objOLApp is nothing then
MsgBox "Could not create OL App. Shutting Down"
Exit Function
End If

'Create a new mail item
Set objMsg = objOLApp.CreateItem(0)
If objMsg is nothing then
MsgBox "Could not create Mail Item. Shutting Down"
Exit Function
End If

'Set basic message parameters
objMsg.To = strRecipient
objMsg.Subject = strSubject
objMsg.Body = strBody

'Send the message
objMsg.Send

'Free up the space
Set objOLApp = Nothing
Set objMsg = Nothing

CreateEmail = "Success"
End Function


VBEnd
Run Program>C:\Program Files (x86)\Microsoft Office\Office14\Outlook.exe
Let>strTo=salesrecipients
vbe>date()-1,mydate
Let>strSubj=Sales: %mydate%
Let>body=
Let>k=1
Label>start
ReadLn>C:\DailySales.txt,k,line
If>line=##EOF##,finish
Let>body=%body%%CRLF%%line%
Let>k=k+1
Goto>start
Label>finish

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Thu Jul 19, 2012 3:11 pm

There is no logic in this script that controls the if/when the email should be sent.

How are you launching the script?
Thanks,
Jerry

[email protected]

jonesey10
Newbie
Posts: 8
Joined: Wed Mar 31, 2010 3:11 pm

Post by jonesey10 » Thu Jul 19, 2012 3:43 pm

It is schedulde using the "Run When" tab in the macroscheduler software.

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Thu Jul 19, 2012 4:37 pm

Could that be the problem?

Because the script is going to run every time it gets launched.
There is no Run/Dont Run logic in the script.
Thanks,
Jerry

[email protected]

jonesey10
Newbie
Posts: 8
Joined: Wed Mar 31, 2010 3:11 pm

Post by jonesey10 » Thu Jul 19, 2012 5:42 pm

Could you give me an example of how to add that to the script? Any help would be greatly appreciated!

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Thu Jul 19, 2012 7:18 pm

What is the condition that will determine whether to email or not?
Thanks,
Jerry

[email protected]

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts