Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with saving attachment to file

Status
Not open for further replies.

slaforce

Programmer
Jul 29, 2002
77
0
0
US
I'm using the following script to save an email attachment to a file. I'm getting a compile error of "Unexpected Next" on line 23. What am I doing wrong?

Function Main()
Set objApp = GetObject(, "Outlook.Application") '#### Find existing instance of Outlook
If Err Then
'WScript.Quit() '#### If Outlook isn't running, quit the script
Set objApp = CreateObject("Outlook.Application") '#### uncomment this & comment out above line to get data even if Outlook isnt running
End If
Set objOutlook = objApp.GetNameSpace("MAPI") '#### Get MAPI namespace

Set objInbox = objOutlook.GetDefaultFolder(6).Items
intA = 0
For Each aMail In objInbox
If aItem.Subject = "test email" Then
Set myattachments = aMail.Attachments
If myattachments.Count > 0 Then
For Each aAttachment In myattachments
Wscript.Echo aMail.Subject & " " & aAttachment.DisplayName
aAttachment.SaveAsFile "C:\" & aAttachment.DisplayName
Next
End If
Next
'set objects to nothing
Set objApp = Nothing
Set objOutlook = Nothing
Set objInboxItems = Nothing

Main = DTSTaskExecResult_Success
End Function
 
Count carefully your If/End If pairs

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top