A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Save e-mail to .msg file



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 17th 09, 07:31 PM posted to microsoft.public.outlook.program_vba
Brad
external usenet poster
 
Posts: 78
Default Save e-mail to .msg file

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
Ads
  #2  
Old July 17th 09, 07:37 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP][_3_]
external usenet poster
 
Posts: 465
Default Save e-mail to .msg file

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).
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Brad" wrote in message
...
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



  #3  
Old July 17th 09, 07:43 PM posted to microsoft.public.outlook.program_vba
Brad
external usenet poster
 
Posts: 78
Default Save e-mail to .msg file

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

"Sue Mosher [MVP]" wrote:

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).
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Brad" wrote in message
...
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




  #4  
Old July 17th 09, 08:09 PM posted to microsoft.public.outlook.program_vba
Brad
external usenet poster
 
Posts: 78
Default Save e-mail to .msg file

Thanks Sue,

It's working perfectly now.

Have a great weekend,

Brad

"Sue Mosher [MVP]" wrote:

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).
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Brad" wrote in message
...
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




  #5  
Old April 10th 10, 01:16 PM posted to microsoft.public.outlook.program_vba
Mojgan Tah
external usenet poster
 
Posts: 1
Default Save e-mail to .msg file

Would you please help me and let me know how your problem for auto save as *.msg was solved .

Thanks in advance for your cooperation .



Brad wrote on Fri, 17 July 2009 15:09
Thanks Sue,

It's working perfectly now.

Have a great weekend,

Brad

"Sue Mosher [MVP]" wrote:

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).
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Brad" wrote in message
...
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





 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to save a email, sent out, as a file DPM Outlook and VBA 4 December 11th 07 05:46 AM
mshtml.Help file is missing. Can't save E-Mail pictures. Andy Outlook Express 10 October 18th 07 03:02 AM
How to automatic save file and forward mail? Mesak Outlook and VBA 1 July 26th 07 03:54 PM
outlook 2k3 Script: how to Save Mail body to txt file news.microsoft.com Outlook and VBA 5 November 7th 06 02:23 PM
trying to save as .msg file !! WhytheQ Outlook and VBA 2 May 26th 06 01:32 PM


All times are GMT +1. The time now is 11:29 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2024 Outlook Banter.
The comments are property of their posters.