Detach Attachments

Hi,Does anyone know how to detach the attachments directly to harddisk using lotus script.It should happen on mails with particular Subject & user.The agent should run on the mail automatically.If not possible automatically then through action menu will also do.

I tried with the the designer help.I pasteing the code .But when I run through action menu, I get the following error “Object variable not set”.

Please find the code below:

Sub Initialize

Dim doc As NotesDocument

Dim rtitem As Variant

Dim fileCount As Integer

Const MAX = 100000

fileCount = 0    

'…set value of doc…

Set rtitem = doc.GetFirstItem( "Body" )

If ( rtitem.Type = RICHTEXT ) Then

Forall o In rtitem.EmbeddedObjects

If ( o.Type = EMBED_ATTACHMENT ) _

And ( o.FileSize > MAX ) Then

fileCount = fileCount + 1

Call o.ExtractFile _

( "c:\IBM" & Cstr(fileCount) )

Call o.Remove

Call doc.Save( True, True )

End If

End Forall

End If

Thanks in advance

Regards

Samir