1

I am completely new to VBA and apologize if this question has already been asked and I am just too much of a noob to find the answer using the correct search terms. What I need is to be able to point a rule in Outlook 2010 to a VBA script that exports the body of the email that triggered the rule to a .csv file which will be used by a PowerShell script that will follow in the rule or possibly be called by the VBA script/macro. The PowerShell script is pretty simple but I need to be able to feed it the information while I am away from my desk and unable to connect to my computer remotely. The body of the email will be standardized to keep it simple and will look like this: Valuename, valuename Value, Value This is all that the email will contain and will be sent as plain text. I have looked through some of the VBA Help files and have not seen anything that I can put together due to my lack of skill with VB. Any assistance pointing me in the right direction to get started on this will be greatly appreciated. Thanks,

VBAnoob
  • 11
  • 1
  • 3
  • http://stackoverflow.com/questions/11876549/how-to-copy-outlook-mail-message-into-excel-using-vba-or-macros/11877451#11877451 – Siddharth Rout Apr 12 '13 at 20:16

2 Answers2

1
Sub SaveEmail(msg As Outlook.MailItem)
    ' save as text
    Dim fn As String
    fn = " *folder to save to* "  & Format(Now, "YYYYMMDD_HHMMSS_") & " *filename* .csv"
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Dim oFile As Object
    Set oFile = fso.CreateTextFile(fn)
    oFile.WriteLine msg.Body
    oFile.Close

## this allows a python script to run or you could call a power script 
## command from here but the key is that the fn is passed to this object
    Shell ("python *python filename*.py " & fn)

End Sub

You then save this into a module and call it using the outlook rules based on the unique message criteria or all messages.

bpython
  • 241
  • 5
  • 15
0

So far you can save the macro as .txt file then import it in excel sheet and save the sheet as cvs. It is a bit complicated but that's what pop up in my mind at first researches. Check this links, and grab the snippets you may find useful:save e-mail as .txt,import .txt in excel,save excel as .cvs.And make sure that you use the correct references for Outlook and Excel.

Community
  • 1
  • 1
Ale
  • 944
  • 3
  • 14
  • 34