Save e-mail to .msg file

B

Brad

Thanks for taking the time to read my question.

I'd like to make a button on my tool bar in Outlook 2007 that will
automatically save the selected e-mail to a predetermined folder. This is
the code I have so far for my macro, but it doesn't work. I get the error
Run-time error '91':
Object variable or With block variable not set

code:
Public Sub ExportSAR()
Dim TheEmail As MailItem
Dim NewFileName As String

NewFileName = InputBox("Enter the SaveAs name", "Save E-mail As", "SAR -
Change - ")

If NewFileName <> "" Then
TheEmail.SaveAs "A:\2009\200907\" & NewFileName, olMSG
Else
MsgBox "No file name was entered. Operation aborted.", 64, "Cancel
Operation"
Exit Sub
End If

End Sub

I can't figure out what I need to fix to make this work. Any help would be
great.

Thanks,

Brad
 
S

Sue Mosher [MVP]

Your code needs a statement to instantiate the TheEmail variable. If you
want the item selected in the current folder view, that would be
Application.ActiveExplorer.Selection(1).
 
B

Brad

Thanks Sue,

I was just lookin at that in the Outlook Developer Reverence - Application
Object Model Map.

I'll try adding this to my code and see what I get.

Brad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top