Probleme using script wizzard scripts

R

Ralf Meuser

Hi there
I try to create a script, which will save attachments from some incomming
mails.
But I'm a small newbee in VB and my script doesn't work.
I got the code from the net and tryed to modifed it, to use it as a script
in outlook 2003 on windows xp.

Thanks in advance for any help

regards

Ralf



here my script
_________________
Sub Test(myItem As MailItem)

'Declaration

Dim myAttachments, myAttachment As Object

Dim myOrt As String

'Dim myOlApp As New Outlook.Application

'Dim myOlExp As Outlook.Explorer

'Dim myOlSel As Outlook.Selection



MsgBox "Mail message arrived:" & myItem.Subject, 1

'# 'Ask for destination folder

'# myOrt = InputBox("Destination", "Save Attachments", "C:\")

myOrt = "C:\tmp\"



'# On Error Resume Next



'# 'work on selected items

'# Set myOlExp = myOlApp.ActiveExplorer

'# Set myOlSel = myOlExp.Selection



'# 'for all items do...

'# For Each myItem In myOlSel



'point on attachments

Set myAttachments = myItem.Attachments



'if there are some...

If myAttachments.Count > 0 Then



'add remark to message text

myItem.Body = myItem.Body & vbCrLf & _

"Removed Attachments:" & vbCrLf



'for all attachments do...

For i = 1 To myAttachments.Count



'save them to destination

myAttachments(i).SaveAsFile myOrt & _

myAttachments(i).DisplayName



'add name and destination to message text

myItem.Body = myItem.Body & _

"File: " & myOrt & _

myAttachments(i).DisplayName & vbCrLf



Next i



'for all attachments do...

While myAttachments.Count > 0



'remove it (use this method in Outlook XP)

'myAttachments.Remove 1



'# 'remove it (use this method in Outlook 2000)

'# myAttachments(1).Delete



Wend



'save item without attachments

myItem.Save

End If



'# Next



'free variables

Set myAttachments = Nothing

Set myAttachment = Nothing

'Set myOlApp = Nothing

'Set myOlExp = Nothing

'Set myOlSel = Nothing

End Sub
 
E

Eric Legault [MVP - Outlook]

First off, it appears that you may be passing myItem to the Test procedure
from somewhere else, perhaps where you are iterating through the Items
collection of your incoming mail folder? Is this the case? I'm a little
confused because you are also working with a collection of selected messages
through ActiveExplorer.Selection. How do you want this to work - with
incoming messages or selected messages?
For fundamentals about automating incoming e-mail messages, there's a
good reference on MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnovba01/html/RulesWizard.asp

Also, both the Attachments.Remove and Attachment.Delete methods are available
in both Outlook 2000 and 2002. Other than that, your code looks fine.


Eric Legault - B.A, MCP, MCSD, Outlook MVP
 
R

Ralf Meuser

Thanks Eric, but know I'm really lost.

I build a rule with will check the subject of incomming mails and when it
fits, it should execute for this mail the script.
On Microsoft site I found this example for the script wizzard:

Sub CustomMailMessageRule(Item As MailItem)
MsgBox "Mail message arrived:" & Item.Subject
End Sub

I thought that everthing I need would be in Item.
The example you talk about (if I'm not mistaken) is for a hole folder. I
just want it for one incomming mail.

best regards


Ralf
 
E

Eric Legault [MVP - Outlook]

Okay, I understand now. Yes, you definitely can do what you are suggesting,
and it looks like you have it setup correctly. You do see your Test procedure
in the list of available scripts for the rule, right? If you uncomment
all the code except the MsgBox line, does that fire? Do you get any specific
errors? Try setting some breakpoints in your code and see where the trouble
is.
Eric Legault - B.A, MCP, MCSD, Outlook MVP
 
S

Sriram N A \(MICO/PJ-SAP-PP\) *

I use a COM add-in called TODI
(www.aufgang.org/koch/homepage/software.asp) - the Windows 2000 beta works
just fine for me (I use Windows 2000 and Outlook 2003). Its freeware. Of
course, it does not react to events, but you can invoke it on a batch of
mail with attachments.
 
R

Ralf Meuser

The problem is nothing happens and I don't know why.
Even the Microsoft exemple don't work.
The rule is ok, since I ask also to print the mail and this works.
I'm really lost.

best regards

Ralf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top