A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

save attachment macro w/ "run a script" rule



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old April 17th 08, 12:20 AM posted to microsoft.public.outlook.program_vba
greg
external usenet poster
 
Posts: 91
Default save attachment macro w/ "run a script" rule

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

lngCounter = objAttachments.Count

If lngCounter 0 Then

'iterate the attachment object collection
For i = lngCounter To 1 Step -1

strFile = objAttachments.Item(i).FileName

strFile = strPath & strFile

Debug.Print strFile

' save the attachment file
objAttachments.Item(i).SaveAsFile strFile

Next i
End If

Set objMail = Nothing
Set objNS = Nothing
Set objAttachments = Nothing

End Sub


--
______
Regards,
Greg
Ads
  #2  
Old April 17th 08, 12:59 AM posted to microsoft.public.outlook.program_vba
JP[_3_]
external usenet poster
 
Posts: 201
Default save attachment macro w/ "run a script" rule

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 -
  #3  
Old April 17th 08, 04:22 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. 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 -

  #4  
Old April 17th 08, 06:31 PM posted to microsoft.public.outlook.program_vba
JP[_3_]
external usenet poster
 
Posts: 201
Default save attachment macro w/ "run a script" rule

I'm finding it difficult to help you because in your first post,
SaveAttachment is accepting a MailItem as an argument, then in your
second post, you ask something completely different and you want to
pass a string, not a MailItem, as an argument.

If you want to use the same macro with different paths, you have to
pass the path to the SaveAttachment macro as an argument. Currently
you have a MailItem (not a string) as the argument for SaveAttachment.

Sub SaveAttachment(MyMail As MailItem)

instead of

Sub SaveAttachment(strPath As String)



If you want to call one macro from another, passing the path to it,
try this:

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

Then SaveAttachment would accept the path as a string like this:

Sub SaveAttachment(sPath As String)
' more code here
End Sub

But you won't be able to do anything with a MailItem unless you pass
it as an argument or find it in an Explorer or Inspector window.


HTH,
JP

On Apr 17, 11:22*am, Greg wrote:
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



  #5  
Old April 17th 08, 06:51 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default save attachment macro w/ "run a script" rule

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 -

  #6  
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 -


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Rule "with specific words.." and "reply with.." works inconsistent ppi Outlook - Installation 2 February 8th 08 06:01 PM
Uncheck all Outlook categories with "run script" rule dpresc Outlook and VBA 4 February 6th 07 07:42 PM
change incoming email attachment default to "open" vs "save as" conroy Outlook - General Queries 1 December 12th 06 01:58 AM
"run a script" rule won't fire macro [email protected] Outlook and VBA 3 October 18th 06 06:08 AM
"Run a script" rule triggers but script does not execute Trey Shaffer Outlook and VBA 7 April 7th 06 11:34 PM


All times are GMT +1. The time now is 03:39 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.