2

My problem is very similar to this thread and this one. I think my issue is to combine these two questions.

I am running:

  • OS: Windows 7 Enterprise Professional
  • Outlook 2010
  • VBA version 7.0

By reading these two questions as well as some other pages from Microsoft and elsewhere, I was able to open the VB editor and paste into it, this simple code:

Sub SaveEmail(msg As Outlook.MailItem)
  ' save as text
  msg.SaveAs "C:\Users\mel\mailsave\email.txt" & Format(Now, "YYYYMMDDHHMMSS"), _
      olTXT
End Sub
  • Is the "format" portion of my msg.SaveAs line, going to save a unique text file for each email matching my rule?
  • How do I run this macro to test and if successful, how do I run it repeatedly?

I tried going to the run menu and selecting run "sub/user form" item but the next dialog box is asking what to run and does not populate a list of macros available for running. Clicked on "save" icon but nothing changed.

Community
  • 1
  • 1
MelBurslan
  • 2,383
  • 4
  • 18
  • 26
  • Is my macro in the code section above, going to generate a unique text file per each message that matches my rule ? How am I going to run this macro first time and subsequent times ? These are my main questions and they are kinda tied together I beleive – MelBurslan Feb 06 '14 at 20:17
  • See how quickly you get decent answers when your question is clear and to the point? – Jean-François Corbett Feb 07 '14 at 07:31
  • Did my suggestion work? :-) – DanL Feb 17 '14 at 21:17

1 Answers1

4

Specifying a method with that signature (Sub method (var As Outlook.MailItem)) allows you to use the method when creating a mailbox rule. As far as I understand your question, you're beyond that point.

Question 1

The format portion of your code is only going to save a unique file at most once per second. You're appending the current date and time to the file. Your main problem, however, is not the timestamp, but the file format. You should apply the timestamp before the file extension, e.g.

msg.SaveAs "C:\Users\mel\mailsave\email" & Format(Now, "YYYYMMDDHHMMSS") & ".txt", olTXT

Question 2

If you add the macro to a rule, it will be run when the rule is matched. The macro can be tested by creating a method that grabs the currently selected mail, e.g.

Sub TestSaveEmail()
   Call SaveEmail(ActiveExplorer.Selection(1))
End Sub

This macro can then be run by setting the cursor within the method and pressing F5.

The macro can also be added to the Outlook user interface by customizing the ribbon and adding a macro button. For help on customizing the ribbon, refer to the following article:

Customize the ribbon

DanL
  • 989
  • 1
  • 8
  • 17