View Single Post
  #1  
Old April 18th 08, 08:49 PM posted to microsoft.public.outlook.program_vba
greg
external usenet poster
 
Posts: 91
Default save attachment macro w/ "run a script" rule

thank you both for your help. It is greatly appreciated.

--
______
Regards,
Greg


"Sue Mosher [MVP-Outlook]" wrote:

First, a macro is an argumentless subroutine, so what you want to call is a sub, not a macro.

It sounds like what you want to do is parameterize the path, in which case, you add it as an argument to the SaveAttachment procedu

Sub SaveAttachment(MyMail As MailItem, strPath as String)

removing, of course, the strPath= statement from that procedure.

To call it, you provide the values for the procedure's arguments:


Sub Save2HM(MyMail As MailItem)
strPath = "\\ad\gbs$\Download\HM\"
Call SaveAttachment(MyMail, strPath)
End Sub

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Greg" wrote in message ...
thank you. will use Option Explicit going forward.

My next question is how to call this macro from the other procedure?
I need several of them for several rules and the only difference will be the
file path.
-----------------------
Sub Save2HM(MyMail As MailItem)

strPath = "\\ad\gbs$\Download\HM\"
Call SaveAttachment

End Sub

then

Sub Save2BLP(MyMail As MailItem)

strPath = "\\ad\gbs$\Download\BLP\"
Call SaveAttachment

End Sub
etc.

Thank you

--
______
Regards,
Greg


"JP" wrote:

You declared "objNS" as the Namespace but you are setting objMail to
"olNS" -- do you see the spelling error there?

Using "Option Explicit" at the top of every module will prevent simple
syntax errors like this.


HTH,
JP


On Apr 16, 7:20 pm, Greg wrote:
hi,

I have the following code i'm having trouble with. it appears to be in the
objects set up. any help is appreciated.

---------------------------------------------
Sub SaveAttachment(MyMail As MailItem)

Dim strID As String
Dim objNS As Outlook.NameSpace
Dim objMail As Outlook.MailItem
Dim objAttachments As Outlook.Attachments
Dim strPath As String, strFile As String

strPath = "\\ad\gbs$\Download\HM\"

strID = MyMail.EntryID
Set objNS = Application.GetNamespace("MAPI")
Set objMail = olNS.GetItemFromID(strID)
Set objAttachments = objMail.Attachments
- snip -


Ads