Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / September 2005

Tip: Looking for answers? Try searching our database.

saving attachments in local map

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Martijn - 05 Sep 2005 12:31 GMT
got a major issue;

I receive xml files by mail and want to save them automaticly in a map.
(my file is called: client.xml)

I found that i had to use VB in outlook and puted in:

thanks to:
http://www.experts-exchange.com/Applications/MS_Office/Outlook/Q_21135312.html

***
Public Sub saveAttachtoDisk (itm As Outlook.MailItem)

Dim objAtt As Outlook.Attachment

Dim saveFolder As String
saveFolder = "c:\temp\"

   For Each objAtt In itm.Attachments
       objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
       Set objAtt = Nothing
   Next
End Sub
*** end code

It is working fine, but the file is overwriting the file that is saved
already.

How can I change the code that if there is a file client.xml the new file is
saved as client (1).xml etc so that the original file doesn't get lost.

Thanx
David Lloyd - 05 Sep 2005 23:53 GMT
Martijn:

One alternative is use the FileSystemObject to check for the existence of
the file.  You will need a reference to the Microsoft Scripting Runtime to
use the FileSystemObject.  The following sample shows one way to accomplish
this task.  This code assumes that the DisplayName property holds a valid
filename with extension.

Public Sub saveAttachtoDisk (itm As Outlook.MailItem)
   Dim fso As New Scripting.FileSystemObject
   Dim objAtt As Outlook.Attachment
   Dim saveFolder As String
   Dim sFileBase As String
   Dim sFile As String
   Dim sExtension As String
   Dim i As Integer
   Dim iPeriod As Integer

   saveFolder = "c:\temp\"
   i = 1
   For Each objAtt In itm.Attachments
       iPeriod = InStrRev(objAtt.DisplayName, ".")
       sFileBase = Left(objAtt.DisplayName, iPeriod - 1)
       sFile = sFileBase
       sExtension = Mid(objAtt.DisplayName, iPeriod)

       Do Until Not fso.FileExists(saveFolder & sFile & sExtension)
           sFile = sFileBase & CStr(i)
           i = i + 1
       Loop
       objAtt.SaveAsFile saveFolder & sFile & sExtension
       Set objAtt = Nothing
       i = 1
   Next

   Set fso = Nothing
   Set objAtt = Nothing
End Sub

Signature

David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.

got a major issue;

I receive xml files by mail and want to save them automaticly in a map.
(my file is called: client.xml)

I found that i had to use VB in outlook and puted in:

thanks to:
http://www.experts-exchange.com/Applications/MS_Office/Outlook/Q_21135312.html

***
Public Sub saveAttachtoDisk (itm As Outlook.MailItem)

Dim objAtt As Outlook.Attachment

Dim saveFolder As String
saveFolder = "c:\temp\"

   For Each objAtt In itm.Attachments
       objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
       Set objAtt = Nothing
   Next
End Sub
*** end code

It is working fine, but the file is overwriting the file that is saved
already.

How can I change the code that if there is a file client.xml the new file is
saved as client (1).xml etc so that the original file doesn't get lost.

Thanx
Martijn - 06 Sep 2005 10:21 GMT
I'm very thankful, you solved my issue!

Great!

> Martijn:
>
[quoted text clipped - 67 lines]
>
> Thanx
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.