1 Replies - 17421 Views - Last Post: 03 March 2009 - 04:08 AM Rate Topic: -----

#1 daneburton  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-November 08

Outlook Macro: Save email to location

Posted 23 November 2008 - 11:57 PM

Hi all.

I am trying to write a Macro inside Outlook 2003. The macro is designed to run through every email inside a selected folder, save each email as a .msg file to a location, then the delete the email from the folder.
See my code below:

Dim sSubject As String
Dim FNme As String
Dim DirName As String
Dim iCount As Integer
Dim itm As Object
DirName = "C:\Documents and Settings\name\Desktop\folder\"

iCount = 1

Set Folder = Outlook.ActiveExplorer.CurrentFolder 'selects the active mailbox

For Each itm In Folder.Items
On Error GoTo ErrorHandler
sSubject = itm.Subject
MsgBox ("Email number: " & iCount & "   Subject: " & sSubject)
FNme = DirName & sSubject & ".msg"
itm.SaveAs FNme, olMSG
itm.Delete

ErrorHandler:
MsgBox ("The email " & sSubject & " failed to save.")
Exit Sub

iCount = iCount + 1
Next

MsgBox ("Emails saved")



When I run the macro in debug mode, it looks like the ErrorHandler is being called at the "itm.SaveAs FNme, olMSG" line.

I am wondering if there is anything wrong with my code that could be causing this? Is the SaveAs function being used properly?
Also, the name of the emails I am trying to save often contain symbols such as * $ @ &, could there be certain characters that cannot be used in a file name? However I don't think this is the problem, as I am able to manually save the emails to the same location (File -> Save As..) without problems.

Oh, and I am using Microsoft XP.

Would appreciate any help I can get.

Cheers.

Is This A Good Question/Topic? 0
  • +

Replies To: Outlook Macro: Save email to location

#2 Yannick74  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-March 09

Re: Outlook Macro: Save email to location

Posted 03 March 2009 - 04:08 AM

View Postdaneburton, on 23 Nov, 2008 - 10:57 PM, said:

Hi all.

I am trying to write a Macro inside Outlook 2003. The macro is designed to run through every email inside a selected folder, save each email as a .msg file to a location, then the delete the email from the folder.
See my code below:

Dim sSubject As String
Dim FNme As String
Dim DirName As String
Dim iCount As Integer
Dim itm As Object
DirName = "C:\Documents and Settings\name\Desktop\folder\"

iCount = 1

Set Folder = Outlook.ActiveExplorer.CurrentFolder 'selects the active mailbox

For Each itm In Folder.Items
On Error GoTo ErrorHandler
sSubject = itm.Subject
MsgBox ("Email number: " & iCount & "   Subject: " & sSubject)
FNme = DirName & sSubject & ".msg"
itm.SaveAs FNme, olMSG
itm.Delete

ErrorHandler:
MsgBox ("The email " & sSubject & " failed to save.")
Exit Sub

iCount = iCount + 1
Next

MsgBox ("Emails saved")



When I run the macro in debug mode, it looks like the ErrorHandler is being called at the "itm.SaveAs FNme, olMSG" line.

I am wondering if there is anything wrong with my code that could be causing this? Is the SaveAs function being used properly?
Also, the name of the emails I am trying to save often contain symbols such as * $ @ &, could there be certain characters that cannot be used in a file name? However I don't think this is the problem, as I am able to manually save the emails to the same location (File -> Save As..) without problems.

Oh, and I am using Microsoft XP.

Would appreciate any help I can get.

Cheers.


Hi Dane,

It's very simple, the SUBJECT couldn't be use in the filename!

You may have some special characters inside this one like : ' \ / etc...

This will make fail the SAVE AS function!

You were onthe right way, the simple things to debug that is to replace SUBJECT bey "test" and it works!

Bye
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1