I have a customer who insists on emailing an excel spreadsheet to me to be uploaded to a sql database. I came across a script at one point that laid out how I would script this out. Basically it was in parts, 1. open email program and get attachment. 2.After saving attachment closing email program in order to be used the next day or next time an attachment was sent. 3. import the attached spreadsheet into SQL database. I would also like to be able to schedule this to run with the built in Windows 2000 scheduler.
Currently I have it set up with the pre-security patched version of Outlook 2k. I would love to have it set up as one job that launches each morning at 8am. Currently I have a script that I run manually that opens Outlook, saves the attachment, moves the message to a subfolder, sends a confirmation email then closes Outlook. It is a wsf file (see below) but when I try to run it as a scheduled task it doesn't do a darn thing.
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objOL = WScript.CreateObject ("Outlook.Application")
Set MAPI = objOL.GetNamespace("MAPI")
Set myStore = MAPI.Folders("Mailbox - Tunisia Information")
Set Folder = myStore.Folders("Inbox")
' Open up the Processed Folder under the inbox
Set DestFldr = Folder.Folders("Processed")
For Each myItem In Folder.Items
For Each att In myItem.Attachments
att.SaveAsFile "\\naslc03\data\TunisiaProdData\" & att.Filename
' Move the Mail to DestFldr
' Create mail message.
Set olMailMessage = objOl.CreateItem(olMailItem)
Set olRecipient = .Recipients.Add("TunisiaProdData@pioneernrc.com")
.Subject = "Tunisia Attachment"
.Body = "The Tunisia email message was created was processed" _
& " and the attachment was successfully saved to the S: Drive."
Set olMailMessage = Nothing
Good - You can try to implement this within dts, using the activex script task. Once this task is complete, you can import the excel file. The easiest way to set this up if you have not worked with dts before, is to go to Enterprise Manager -> Databases -> The database you want to import into -> tables. Right click on tables -> All tasks -> Import Data. Follow the instructions - making sure at the end to save it. When you have saved it, you can modify the package under Data Transformation Services -> Local Packages. Open your package in design mode and create an activex script task. Insert your code into that task and run that step to see if it will function properly.
If adding it as an activex script does not work, you can still keep the rest of the package (the excel import). When you create a job based on this package, you can add a step that will execute an operating system command (which would be your script).