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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB code used in Outlook???

Status
Not open for further replies.

Mungovan

Programmer
Oct 24, 2002
94
IE
Hi.
Maybe someone can help me with this code. This code is in an Outlook form that I use on a folder in Outlook called Import. The folder contains e-mails that all have Excel attachments. When the program runs, it loops through all the e-mails and makes a copy of their attachments, saving them in the folder "F:\Settlements\Import".
But there are two problems. It's saving the files in the Settlements folder and placing the word "Import" infront of the file name.

Also, I need to move the e-mails to a different folder after it has copied and pasted its attachments. I think the line:
objItem.Move 'New folder
Will work, but how do I enter the path of the new folder, which is an Outlook folder called Old??

Anyway, here is the code I'm using for the form. Thanks for any help anyone can give me!!! :)

D


option explicit

Function Item_Open()

dim objNameSpace
dim objFolder
dim objItem
dim objAttachment
dim intIndex
dim intIndex2
dim strFiles

set objNameSpace = Application.GetNameSpace("MAPI")
set objFolder = objNameSpace.PickFolder


for intIndex = 1 to objFolder.Items.Count
set objItem = objFolder.Items(intIndex)
if objItem is nothing then
else
for intIndex2 = 1 to objItem.Attachments.Count
set objAttachment = objItem.Attachments(intIndex2)
if objAttachment is nothing then
else
objAttachment.SaveAsFile "c:import\" & objAttachment.FileName
strFiles = strFiles & objAttachment.FileName & vbCR
end if
next
end if
next

Item.Body = strFiles

End Function
 
* to remove the "import" at the beginning of your attachment modify your code like this:

objAttachment.SaveAsFile = objAttachment.FileName

* to save the attachment on a differnet folder,

dim strPath as String
dim strFilename as String

strPath = "C:\Import"
strFilename = objAttachment.FileName

objAttachment. SaveAsFile (strPath & "\" & strFilename)



kindly check the syntax to conform with your code. hope this works.

:)


 
Hi.
Thanks, that worked grand!!

One more quick question. After the attachments have been moved to the F: drive I'd like to move all the e-mails to an Outlook folder called "Old". Do you know how this can be done??

Thanks a million,
D
 
you mean the folder "Old" is not a physical folder on any of your drives?
 
This code is great but what if i only wanted to specify one specific folder within my Outlook user account

Never ever, bloody anything, ever
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top