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

Trying to have code close an open email after it saves.



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old November 4th 08, 03:24 PM posted to microsoft.public.outlook.program_vba
DStrong
external usenet poster
 
Posts: 18
Default Trying to have code close an open email after it saves.

Using outlook 2003 I am trying to get outlook to close the currently opened
email after it saves it. I have got everything working but the closeing part.
Can someone give me some ideas, suggestions or the write code to get this to
work. Here is what I have at this point:

Sub SaveAsOF()
'## Saves current email to users My Documents and Emails folder
Dim myItem As Outlook.Inspector
Dim objItem As Object

Set myItem = Application.ActiveInspector
If Not TypeName(myItem) = "Nothing" Then
Set objItem = myItem.CurrentItem
strname = objItem.Subject
strInvalidSequences = "`+
+~+!+@+$+%+^+&+*+=+{+}+[+]+|+\+""+:+;+++/"
strArrInvalidSequence = Split(strInvalidSequences, "+")

For x = 0 To UBound(strArrInvalidSequence)
Text = strArrInvalidSequence(x)
strname = Replace(strname, Text, "_")
Next x
strpath = Environ("HOMEdrive") & "My Documents\Emails\" & strname &
".msg"
'Prompt the user for confirmation
Dim strPrompt As String
strPrompt = "The email has been saved as " & strpath
CheckFolder
objItem.SaveAs Environ("HOMEdrive") & "\My Documents\Emails\" &
strname & ".msg", olMSG
MsgBox (strPrompt)
Else
MsgBox "You must open the email to save it, please double click the
email and try again."
End If
End Sub

Sub CheckFolder()
Dim fso
Dim fol As String
fol = Environ("HOMEdrive") & "My Documents\Emails"
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(fol) Then
fso.CreateFolder (fol)
End If
End Sub

Since some people do not have the "Emails" folder the second macro included
here adds it. Thanks in advance for any help on this.
Ads
  #2  
Old November 4th 08, 04:17 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Trying to have code close an open email after it saves.

You can use the Save event of the item once you have a reference to the item
to do that. Just call the Close method on the item during the Save event.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"DStrong" wrote in message
...
Using outlook 2003 I am trying to get outlook to close the currently
opened
email after it saves it. I have got everything working but the closeing
part.
Can someone give me some ideas, suggestions or the write code to get this
to
work. Here is what I have at this point:

Sub SaveAsOF()
'## Saves current email to users My Documents and Emails folder
Dim myItem As Outlook.Inspector
Dim objItem As Object

Set myItem = Application.ActiveInspector
If Not TypeName(myItem) = "Nothing" Then
Set objItem = myItem.CurrentItem
strname = objItem.Subject
strInvalidSequences = "`+
+~+!+@+$+%+^+&+*+=+{+}+[+]+|+\+""+:+;+++/"
strArrInvalidSequence = Split(strInvalidSequences, "+")

For x = 0 To UBound(strArrInvalidSequence)
Text = strArrInvalidSequence(x)
strname = Replace(strname, Text, "_")
Next x
strpath = Environ("HOMEdrive") & "My Documents\Emails\" & strname &
".msg"
'Prompt the user for confirmation
Dim strPrompt As String
strPrompt = "The email has been saved as " & strpath
CheckFolder
objItem.SaveAs Environ("HOMEdrive") & "\My Documents\Emails\" &
strname & ".msg", olMSG
MsgBox (strPrompt)
Else
MsgBox "You must open the email to save it, please double click the
email and try again."
End If
End Sub

Sub CheckFolder()
Dim fso
Dim fol As String
fol = Environ("HOMEdrive") & "My Documents\Emails"
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(fol) Then
fso.CreateFolder (fol)
End If
End Sub

Since some people do not have the "Emails" folder the second macro
included
here adds it. Thanks in advance for any help on this.


  #3  
Old November 4th 08, 05:19 PM posted to microsoft.public.outlook.program_vba
DStrong
external usenet poster
 
Posts: 18
Default Trying to have code close an open email after it saves.

Thanks for the reply. I have tried adding "Close" at the end of my saveas
statement and it askes for an expression. I have tried "objItem Close",
"Close.objItem", "Close" all after my msgbox and still no luck. I have tried
to read up on the Close method and can't see to figure out how to format it
as well as what you just suggested. I guess that I am putting something in
the wrong place or something.

David

"Ken Slovak - [MVP - Outlook]" wrote:

You can use the Save event of the item once you have a reference to the item
to do that. Just call the Close method on the item during the Save event.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"DStrong" wrote in message
...
Using outlook 2003 I am trying to get outlook to close the currently
opened
email after it saves it. I have got everything working but the closeing
part.
Can someone give me some ideas, suggestions or the write code to get this
to
work. Here is what I have at this point:

Sub SaveAsOF()
'## Saves current email to users My Documents and Emails folder
Dim myItem As Outlook.Inspector
Dim objItem As Object

Set myItem = Application.ActiveInspector
If Not TypeName(myItem) = "Nothing" Then
Set objItem = myItem.CurrentItem
strname = objItem.Subject
strInvalidSequences = "`+
+~+!+@+$+%+^+&+*+=+{+}+[+]+|+\+""+:+;+++/"
strArrInvalidSequence = Split(strInvalidSequences, "+")

For x = 0 To UBound(strArrInvalidSequence)
Text = strArrInvalidSequence(x)
strname = Replace(strname, Text, "_")
Next x
strpath = Environ("HOMEdrive") & "My Documents\Emails\" & strname &
".msg"
'Prompt the user for confirmation
Dim strPrompt As String
strPrompt = "The email has been saved as " & strpath
CheckFolder
objItem.SaveAs Environ("HOMEdrive") & "\My Documents\Emails\" &
strname & ".msg", olMSG
MsgBox (strPrompt)
Else
MsgBox "You must open the email to save it, please double click the
email and try again."
End If
End Sub

Sub CheckFolder()
Dim fso
Dim fol As String
fol = Environ("HOMEdrive") & "My Documents\Emails"
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(fol) Then
fso.CreateFolder (fol)
End If
End Sub

Since some people do not have the "Emails" folder the second macro
included
here adds it. Thanks in advance for any help on this.



  #4  
Old November 4th 08, 05:58 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Trying to have code close an open email after it saves.

Just use myItem.Close(olDiscard) since you have that as an Inspector
reference.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"DStrong" wrote in message
...
Thanks for the reply. I have tried adding "Close" at the end of my saveas
statement and it askes for an expression. I have tried "objItem Close",
"Close.objItem", "Close" all after my msgbox and still no luck. I have
tried
to read up on the Close method and can't see to figure out how to format
it
as well as what you just suggested. I guess that I am putting something in
the wrong place or something.

David


  #5  
Old November 4th 08, 06:11 PM posted to microsoft.public.outlook.program_vba
DStrong
external usenet poster
 
Posts: 18
Default Trying to have code close an open email after it saves.

Thanks so much Ken, BTW do you have a book for VBA or Outlook? I have Sue's
programming one, but the more I can learn then better.

David

"Ken Slovak - [MVP - Outlook]" wrote:

Just use myItem.Close(olDiscard) since you have that as an Inspector
reference.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"DStrong" wrote in message
...
Thanks for the reply. I have tried adding "Close" at the end of my saveas
statement and it askes for an expression. I have tried "objItem Close",
"Close.objItem", "Close" all after my msgbox and still no luck. I have
tried
to read up on the Close method and can't see to figure out how to format
it
as well as what you just suggested. I guess that I am putting something in
the wrong place or something.

David



  #6  
Old November 4th 08, 07:46 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Trying to have code close an open email after it saves.

See my signature

My book does have some on VBA and forms but is geared to more advanced
topics such as COM addins and concentrates on Outlook 2007.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"DStrong" wrote in message
...
Thanks so much Ken, BTW do you have a book for VBA or Outlook? I have
Sue's
programming one, but the more I can learn then better.

David


 




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 close active-form and open a new one Boein Outlook - Using Forms 4 May 27th 08 02:05 PM
Automatic Maintenance from each 100 open/close to 200? Alex Tolle [Alcahest] Outlook Express 1 March 6th 07 03:22 AM
how do I close outlook 2003 to retain the calendars that are open mmstokes4477 Outlook - Calandaring 3 February 28th 07 08:31 PM
Macro button that saves the email I'm reading to c:\outlook as .ms kvpb2000 Outlook and VBA 6 November 2nd 06 09:47 AM
Which event is triggered when user saves email item? Kasper Add-ins for Outlook 4 September 22nd 06 02:26 PM


All times are GMT +1. The time now is 03:39 PM.


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