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!

moving attachments from outlook

Status
Not open for further replies.

ApplePirate

Programmer
Dec 16, 2002
65
GB
Someone please help
Im new to VB and cant seem to get this code to work,


---------------------------------------------------
Function Item_Open()
dim objNameSpace
dim objFolder
dim objItem
dim objAttachment
dim intIndex
dim intIndex2
dim strFiles
dim DefaultFolder
set DefaultFolder = Item.("Scottish Southern")
set objNameSpace = Application.GetNameSpace("MAPI")
set objFolder = objNameSpace.Folder
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 "T:\Developer Partnerships\File Loading Area\Quadrant\" & objAttachment.FileName
strFiles = strFiles & objAttachment.FileName & vbCR
end if
next
end if
next
Item.Body = strFiles
End Function
---------------------------------------------------

i get an error:-
Object required: '(string: "Scottish Southern")' Line No: 10

im trying to preset the folder that the code looks in to strip out attachments.

someone must be able to help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1

 
I take it you have fixed the problem that you had in thread222-591834? If so then you can use the GetDefaultFolder as was suggested before.
 
as i mentioned before. there arent any options as i type.
im using the script editor which i access by opening a mail item in design view and then viewing the code. Most of the code posted here seems to have "Dim Name as Value" for example which my script editor seems to reject, it will accept "Dim Name" but if you tag on the "as Value" and then run, it throws up an error.
On the the post which originally had the script, it has a pop up window from which you select the folder to strip all attachments from. I want the folder to be coded into the script. so when the item is opened it just runs automatically. once the attachments have been moved an access database then imports each item to a temp table cleans them up and appends them to a working table

I have to have a process that a monkey could do, unfortunately im feeling like the monkey at the moment.


PLEASE SOMEONE HELP!!!!!!!!!!!!!!!!!!!!


 
>>set DefaultFolder = Item.("Scottish Southern")
set objNameSpace = Application.GetNameSpace("MAPI")
set objFolder = objNameSpace.Folder
<<

These statements appear to be nonsense. Are you trying to process all items in a MAPI folder named Scottish Southern? What's the path to the folder? Is Outlook in Corporate/Workgroup or Internet Only mode?

The standard Outlook forms that you can customise only support development in VBScript. The script editor window is very simple, nothing like VB. VBScript variables are all variants; they can't be declared as a type. VBScript also has a smaller range of built in functions than VB.

Outlook 2000 and later has VBA which provides an IDE similar to VB. From the Outlook menu, Tools | Macros | Visual Basic Editor. You can add forms and modules to the project just like VB.

Paul Bent
Northwind IT Systems
 
Thanks for the response Paul you clarified a lot for me.
The statements probably are nonsense, because im a new user of VB and struggling. I cant seem to find what version of outlook im using. If it helps im employed by a large company and i think we have an exchange server? which is why i had a niggly feeling i was using a crap version of outlook (we still use Access 97) But i have located the VB script editor in Excell so im also inclined to think that the VB editor in Outlook has been switched off due to possible virus issues.
The path to the folder in my outlook is:-
My mailbox/Inbox/Mowlem



 
Merry Xmas?


Private Sub Application_NewMail()
Dim newMsg As Integer


Set myOlApp = CreateObject(&quot;Outlook.Application&quot;)
Set myNamespace = myOlApp.GetNamespace(&quot;MAPI&quot;)
Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox)

c = myFolder.Items.Count

For newMsg = c To 1 Step -1

Set myitem = myFolder.Items(c)
Set myAttachments = myitem.Attachments
If myitem.UnRead = False Then Exit For
If myAttachments.Count > 0 Then


myitem.Display

Set myitem = myOlApp.ActiveInspector.CurrentItem
Set myAttachments = myitem.Attachments
myAttachments.Item(1).SaveAsFile &quot;C:\Outlook Attachments\&quot; & myAttachments.Item(1).DisplayName
myitem.Close olDiscard
Else
Exit Sub
End If
Next newMsg

End Sub


[yinyang] Tranpkp [pc2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top