Macro to save attachment and re email
I have a VBS script to auto save specific emails with attachemnts. It then gens a mail.bat file to send the saved attachment via email to a UNIX sever. This wortks great with one excpetion. It never run the mail.bat program. See the line in RED. I am including the script. Can anyone help me understand why it does not run the bat file? Sub AltSaveSCC() Dim oApp As Application Dim oNS As NameSpace Dim oMsg As Object Dim oAttachments As Outlook.Attachments Dim strControl Set oApp = New Outlook.Application Set oNS = oApp.GetNamespace("MAPI") Set oFolder = oNS.GetDefaultFolder(olFolderInbox) strControl = 0 For Each oMsg In oFolder.Items With oMsg If .subject Like "*SCC data*" Then strControl = strControl + 1 oMsg.Attachments.Item(1).SaveAsFile "C:\scc\in\" & strControl & "scc-transfer-data.gz" MsgBox "The SCC data has been processed" Call Mail("C:\scc\in\" & strControl & "scc-transfer-data.gz", .subject) End If End With NextEnd Sub'--------------------------------------------------------------------------'--- Mail(SendFile)'---'--- Mail specified filename'---'--- SendFile filename to send (including path)'--------------------------------------------------------------------------Sub Mail(SendFile, MsgSub)On Error Resume Next Dim FSO_Temp 'Filesystem object Dim ObjShell 'shell object Dim TextStreamTemp 'textstream Dim runCommand, CD_Command 'strings Dim batchfile 'strings batchfile = "mail.bat" mailTo = "scc-transfer@chaos.arinc.com" mailFrom = "sjones@arinc.com" smtpServer = "cismailrelay.arinc.com" strSccPath = "c:\scc\in" '---Create Filesystem Object Set FSO_Temp = CreateObject("Scripting.FileSystemObject") '---Create command batchfile Set TextStreamTemp = FSO_Temp.CreateTextFile(strSccPath & "\" & batchfile) TextStreamTemp.Writeline (Chr(34) & "C:\Program Files\SCC\bin\blat.exe" & Chr(34) & " " & Chr(34) & SendFile & Chr(34) & _ " -uuencode -s " & Chr(34) & MsgSub & Chr(34) & _ " -t " & mailTo & " -f " & mailFrom & " -server " & smtpServer) TextStreamTemp.Close '---Create Shell object and run command Set ObjShell = CreateObject("WScript.Shell") If GetOS = "Microsoft Windows" Then CD_Command = "command /c cd " & Chr(34) & strSccPath & Chr(34) runCommand = "command /c " & batchfile Else 'NT or 2000 CD_Command = "cmd cd " & Chr(34) & strSccPath & Chr(34) runCommand = "cmd " & strSccPath & "\" & batchfile End If '---Send the snapshot by running batch file'--- ObjShell.run CD_Command, 0, True 'ObjShell.run CD_Command, 4, True ObjShell.Run runCommand, 4, True MsgBox "The SCC data has been mailed using: " & runCommand '---Remove used tempfiles'--- FSO_Temp.DeleteFile (strSccPath & "\" & batchfile)'--- FSO_Temp.DeleteFile (SendFile)End Sub
August 15th, 2006 8:51pm

There is a newsgroup specifically for general Outlook programming issues at http://www.microsoft.com/office/community/en-us/default.mspx?dg=microsoft.public.outlook.program_vba. But this isn't really an Outlook question, is it? It seems more like an issue about how to get your WScript.Shell to run your batch file, a subject about which I unfortunately know nothing.
Free Windows Admin Tool Kit Click here and download it now
August 22nd, 2006 9:06pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics