Solved

How do I schedule an excel file to be sent automatically via email

Posted on 2013-01-16
5
360 Views
Last Modified: 2013-02-16
I would like to automate the sending of an excel spreadsheet via email to be triggered on a schedule defined in windows 7. Is it possible to use the task scheduler? IF so how?
0
Comment
Question by:mbs2000
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:Alex_W
ID: 38783329
This may be of some use:

http://www.outlookforums.com/threads/34063-auto-send-attachment/

I think you may end up with a plug in or 3rd party application.
0
 
LVL 9

Accepted Solution

by:
TazDevil1674 earned 250 total points
ID: 38783367
There are many ways this could be done using either Batch File or VBS.


VBS Example

Set outobj = CreateObject("Outlook.Application")
Set mailobj = outobj.CreateItem(0)
Set fso = CreateObject("Scripting.FileSystemObject")

SigString = "C:\Users\USER\AppData\Roaming\Microsoft\Signatures\Signature.htm"

If fso.FileExists(SigString) Then
	Signature = GetBoiler(SigString)
Else
	Signature = ""
End If

With mailobj
	'.SentOnBehalfOfName = 
	.To = "alpha@domain.com"
	.CC = "beta@domain.com" & ";" & "charlie@domain.com"
	.Subject = "Automated Report"
	'.Body = "As requested, please see attached..." & vbNewLine & Signature
	.HTMLBody = "<HTML>" & _
        "<p style='font-family:calibri;font-size:14'>" & _
		"As requested, please see attached..." & _
		"<BR><BR>" & Signature & _
		"</HTML>"
	.Attachments.Add "\\unc_server_anme\share\file.pdf"
	.Attachments.Add "D:\files\excel.xls"
	' uncomment .Send to send automatyically - comment out .Display
                .Display
	'.Send
End With

'Clear the memory
Set outobj = Nothing
Set mailobj = Nothing

Function GetBoiler(ByVal sFile ) 'As String) 'As String
'Dick Kusleika
    Dim fso 'As Object
    Dim ts 'As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
    GetBoiler = ts.readall
    ts.Close
End Function

Open in new window


Batch File Example
Set objEmail = CreateObject("CDO.Message")

objEmail.From = "helpdesk@fabrikam.com"
objEmail.To = "administrator@fabrikam.com"
objEmail.Subject = "Server down" 
objEmail.Textbody = "Server1 is no longer accessible over the network."
objEmail.AddAttachment "C:\Scripts\Output.txt"

objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
        "smtpmailer" 
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update

objEmail.Send

Open in new window


Batch file would be good if you may not be logged on or have outlook open...  

You could then set up a scheduled task to run either...
0
 
LVL 8

Assisted Solution

by:d0ughb0y
d0ughb0y earned 250 total points
ID: 38783403
If you're using Outlook, an approach that I have seen in the past (not recently, mind you) is to use an Outlook add-on, like Slipstick. That should be able to do what you're asking, but it is shareware, and ultimately, you'd have to pay for it.

If you're not using Outlook, then you can use the scheduler to send it, but you're going to need to do a little coding, and/or use some tools to get it done. I've done it with Google, for example, by downloading and using SendEmail for Windows, or Blat for Windows.

I've used both, but the one I remember best was SendEmail. The command that you're going to set as your action is going to be something like this. (Remember, I'm using Google as my host here.)
sendemail.exe -f <your email address> -t <the target email address> -u <your subject line> -m <your message> -a <the complete path to the file> -s smtp.gmail.com:587 -xu <your login account - could be the same as your email address> -xp <your account password> -o tls=yes

That's what you'd use. You could put it into a batch file, and then call that from the scheduler. Or you could just use sendemail.exe as the action, and that long string as the optional parameters. Make sure you use the folder where you have the sendemail executable, as the Start In folder.
0
 
LVL 8

Expert Comment

by:d0ughb0y
ID: 38783439
Just wanted to point out that the "Batch file" listed above, isn't a batch file. It's VBS as well. Try typing any of those commands at the C:\ prompt, and see what happens. Heck, try typing them at the PowerShell prompt and see what happens.

That said, that VBS would probably do the job too.
0
 
LVL 9

Expert Comment

by:TazDevil1674
ID: 38783534
@d0ughb0y, thanks for spotting that...  brain not working fully today!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to read BOM (Byte Order Mark) from csv file. 4 35
Excel for Mac - How make those Tabs larger? 2 30
Boolean help 6 27
FormulaArray VBA Issue 6 17
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

947 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now