look at this, it uses the Current Session of Outlook:
Dim olObj
Set olObj = CreateObject("Outlook.Application"
Set MyNameSpace = olObj.getNameSpace("MAPI".getDefaultFolder(6)
Set myInboxItems = myNameSpace.Items
For i = 1 To 1
Set InbxItms = myInboxItems(i)
With InbxItms
WScript.Echo(i&vbTab&"UNREAD STATUS : " &.unread)
WScript.Echo(vbTab&"DATE : "&.CreationTime)
WScript.Echo(vbTab&"FROM : "&.sendername)
WScript.Echo(vbTab&"TO : "&.to)
WScript.Echo(vbTab&"SUBJECT : "&.subject)
If .attachments.count = 0 Then
WScript.Echo(vbTab&"ATTACHMENTS : NONE"
else
For p = 1 To .attachments.count
WScript.Echo(vbTab&"ATTACHMENT : " &.attachments(p))
.SaveAs "c:\temp\"&.attachments(p)
Next
end If
.close(i)
End With
WScript.Echo("-------------------------------------------------------------"
next
Set myItem = nothing
Set myItems = nothing
Set myInbox = nothing
Set MyNameSpace = Nothing
Set olObj = Nothing
the wscript.echo just puts output to the screen. if you do not care about seeing the output then you can delete the wscript lines.
so try this:
Dim olObj
Set olObj = CreateObject("Outlook.Application"
Set MyNameSpace = olObj.getNameSpace("MAPI".getDefaultFolder(6)
Set myInboxItems = myNameSpace.Items
For i = 1 To 1
Set InbxItms = myInboxItems(i)
With InbxItms
If .attachments.count = 0 Then
WScript.Echo(vbTab&"ATTACHMENTS : NONE"
else
For p = 1 To .attachments.count
.SaveAs "c:\temp\"&.attachments(p)
Next
end If
.close(i)
End With
next
Set myItem = nothing
Set myItems = nothing
Set myInbox = nothing
Set MyNameSpace = Nothing
Set olObj = Nothing
I should also mention that i = 1 To 1 will only look at the first message in the outlook inbox. You will need at adjust this to go through all the messages in the inbox. You can try i = 1 to myInboxItems.count. I have not tested though. Hope this helps
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.