Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook and VBA (http://www.outlookbanter.com/outlook-vba/)
-   -   Saving email attachments (http://www.outlookbanter.com/outlook-vba/80570-saving-email-attachments.html)

Nigel RS October 21st 08 12:48 PM

Saving email attachments
 
I am using the following code, that runs from an outlook rule, to save
attachments
to a path defined by the contents of the email body. For example in my
email body I have the text string
D:\

I receive an error despite the path and file looking OK.

Help!

Sub ANYPATH(itm As Outlook.MailItem)

Dim objatt As Outlook.Attachment
Dim SaveFolder As String
SaveFolder = Trim(itm.Body)

For Each objatt In itm.Attachments
objatt.SaveAsFile SaveFolder & objatt.DisplayName
Next

Set objatt = Nothing

End Sub

Ken Slovak - [MVP - Outlook] October 21st 08 02:42 PM

Saving email attachments
 
The code looks OK offhand, what sort of path strings are you getting? Do the
paths other than the file name actually exist?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Nigel RS" wrote in message
...
I am using the following code, that runs from an outlook rule, to save
attachments
to a path defined by the contents of the email body. For example in my
email body I have the text string
D:\

I receive an error despite the path and file looking OK.

Help!

Sub ANYPATH(itm As Outlook.MailItem)

Dim objatt As Outlook.Attachment
Dim SaveFolder As String
SaveFolder = Trim(itm.Body)

For Each objatt In itm.Attachments
objatt.SaveAsFile SaveFolder & objatt.DisplayName
Next

Set objatt = Nothing

End Sub



Nigel RS October 21st 08 03:03 PM

Saving email attachments
 
Hi Ken
I get the path D:\myfile.xls (for example) which is a valid path, yet the
message from Outlook says...

Runtime error - 1525219205
Cannot save the attachment. Filename or directory name is not valid.

In debug: SaveFolder shows: D:\
objatt.name returns: myfile.xls

I wonder if it is the local path mapping that failing, the server is network
based but the rule runs in local client.

"Ken Slovak - [MVP - Outlook]" wrote:

The code looks OK offhand, what sort of path strings are you getting? Do the
paths other than the file name actually exist?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Nigel RS" wrote in message
...
I am using the following code, that runs from an outlook rule, to save
attachments
to a path defined by the contents of the email body. For example in my
email body I have the text string
D:\

I receive an error despite the path and file looking OK.

Help!

Sub ANYPATH(itm As Outlook.MailItem)

Dim objatt As Outlook.Attachment
Dim SaveFolder As String
SaveFolder = Trim(itm.Body)

For Each objatt In itm.Attachments
objatt.SaveAsFile SaveFolder & objatt.DisplayName
Next

Set objatt = Nothing

End Sub




Nigel RS October 21st 08 03:22 PM

Saving email attachments
 
Hi Ken
I have changed the path by setting it directly

SaveFolder = "D:\"

not from itm.Body and it works OK!!

Very strange, as in debug mode the text string looks identical.

"Ken Slovak - [MVP - Outlook]" wrote:

The code looks OK offhand, what sort of path strings are you getting? Do the
paths other than the file name actually exist?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Nigel RS" wrote in message
...
I am using the following code, that runs from an outlook rule, to save
attachments
to a path defined by the contents of the email body. For example in my
email body I have the text string
D:\

I receive an error despite the path and file looking OK.

Help!

Sub ANYPATH(itm As Outlook.MailItem)

Dim objatt As Outlook.Attachment
Dim SaveFolder As String
SaveFolder = Trim(itm.Body)

For Each objatt In itm.Attachments
objatt.SaveAsFile SaveFolder & objatt.DisplayName
Next

Set objatt = Nothing

End Sub




Nigel RS October 21st 08 04:07 PM

Saving email attachments
 
Sorted - there are non-printable characters in the MailItem.Body, I have put
in a function to strip these out and everything works as expected.

Cheers

"Nigel RS" wrote:

Hi Ken
I have changed the path by setting it directly

SaveFolder = "D:\"

not from itm.Body and it works OK!!

Very strange, as in debug mode the text string looks identical.

"Ken Slovak - [MVP - Outlook]" wrote:

The code looks OK offhand, what sort of path strings are you getting? Do the
paths other than the file name actually exist?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Nigel RS" wrote in message
...
I am using the following code, that runs from an outlook rule, to save
attachments
to a path defined by the contents of the email body. For example in my
email body I have the text string
D:\

I receive an error despite the path and file looking OK.

Help!

Sub ANYPATH(itm As Outlook.MailItem)

Dim objatt As Outlook.Attachment
Dim SaveFolder As String
SaveFolder = Trim(itm.Body)

For Each objatt In itm.Attachments
objatt.SaveAsFile SaveFolder & objatt.DisplayName
Next

Set objatt = Nothing

End Sub




Ken Slovak - [MVP - Outlook] October 21st 08 04:13 PM

Saving email attachments
 
Maybe some non-printable character when you take the string from Body? I
wonder if your code is picking up any newlines (vbCRLF) or something like
that?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Nigel RS" wrote in message
...
Hi Ken
I have changed the path by setting it directly

SaveFolder = "D:\"

not from itm.Body and it works OK!!

Very strange, as in debug mode the text string looks identical.



gp October 24th 08 10:21 PM

Saving email attachments
 
Nigel,

I have been looking for a function to remove non-printable characters from
e-mail subject text. Can you share your function?

Thanks, GP


"Nigel RS" wrote:

Sorted - there are non-printable characters in the MailItem.Body, I have put
in a function to strip these out and everything works as expected.

Cheers

"Nigel RS" wrote:



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-2006 OutlookBanter.com