Outlook 2003 - Add toggle to keep in Sent Items in toolbar

Hi,

Is there a way to add a button on the toolbar when writing new emails or replying to existing ones to toggle whether the email is saved in Sent Items or not? This is to avoid having to click Options and change it from there.

Thanks.
inforrAsked:
Who is Participating?
 
Chris RaisinConnect With a Mentor (Retired Analyst/Programmer)Commented:
OK...Here are the instructions for adding the button which activates the code in the macro.

If you need any instructions on how to add the macro code, just let me know.
(I was assuming you can use the Visual Basic Editor in Outlook but if that is not the case, just let me know).

Hope this is what you were after....
SaveInSent-1.jpg
SaveInSent-2.jpg
SaveInSent-3.jpg
SaveInSent-4.jpg
SaveInSent-5.jpg
SaveInSent-6.jpg
SaveInSent-7.jpg
SaveInSent-8.jpg
SaveInSent-9.jpg
SaveInSent-10.jpg
SaveInSent-11.jpg
SaveInSent-12.jpg
SaveInSent-13.jpg
SaveInSent-14.jpg
SaveInSent-15.jpg
0
 
David LeeCommented:
Hi, inforr.

Yes, that's possible.  There might be an easier way though, and one that will prevent you from forgetting to click the button.  How about a dialog-box that asks you where you want to file the item when you send it?
0
 
inforrAuthor Commented:
Hi BlueDevilFan,

Yep that would work.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
David LeeCommented:
Ok, this should do it.  The code will prompt you with the question "Should I file a copy of this item in Sent Items?" each time you send something.  If you click Yes, then a copy will go to Sent Items.  click No and the sent item will go wherever you've defaulted sent items to go.

Follow these instructions to add the code to Outlook.

1.  Start Outlook
2.  Click Tools > Macro > Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of
5.  Outlook's VB Editor window
6.  Edit the code as needed.  I included comment lines wherever something needs to or can change
7.  Click the diskette icon on the toolbar to save the changes
8.  Close the VB Editor
9.  Click Tools > Macro > Security
10. Set the Security Level to Medium
11. Close Outlook
12. Start Outlook
13. Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run.  Say yes.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    If MsgBox("Should I file a copy of this item in Sent Items?", vbQuestion + vbYesNo, "File Sent Item") = vbYes Then
        Set Item.SaveSentMessageFolder = Session.GetDefaultFolder(olFolderSentMail)
        Item.Save
    End If
End Sub

Open in new window

0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
I am writing a bit of code for you now to toggle a button as requested - please give me 20 minutes.
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
Taking a bit longer than I thought.....stand by
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
Can you please clarify?

Are you trying to stop the messages being saved in the "Sent" folder?
(I'm not sure you can, since it breaches security) or are you just trying to
get around the pop-up box that appears for "Send/Recieve" when you send a message (so sometimes you can see the Send/Receive" progress box and (if desired) at other times you won't.
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
OOps...forget that last question....I just realised which option you are talking about....

Please stand by
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
Success!  Now just give me a moment to upload everything.
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
Here is the code.

Instructions on how to add the button will follow (taking me a while to prepare screen captures)
Option Explicit
Public Sub ToggelSaveInSent()
   'This subroutine simply toggles a value in the registry to record 
   'whether the current user wishes to store copies of sent items in 
   'the SENT folder or not, by use of a button on the Standard Menu
   'in a NEW email message being created.
  
  Dim oBar As CommandBar  'The "Standard" command bar in your Outlook
                          'message area
  Dim oControls As Office.CommandBarControls 
                          'The controls (buttons etc.) on that
                          'command bar
  Dim x As Integer        'Used to scan the controls to find 
                          'our "InSent" button
  Dim bButton As CommandBarControl
                          'Our Button!
  Dim bSaveInSent As Boolean 
                          'Holds current state of whether we
                          'want to save or not (True/False)
  
  'gather data from our Standard toolbar
  Set oBar = Application.ActiveWindow.CommandBars("Standard")
  Set oControls = oBar.Controls

  'Find our button on the toolbar
  For x = 1 To oControls.Count
    'if the words "Insent:" appear somewhere on the control 
    'we are currently looking at,
    If InStr(oControls.Item(x).Caption, "InSent:") > 0 Then
      'then this is our button!
      Set bButton = oBar.Controls.Item(x)
      'No need to look any further!
      Exit For
    End If
  Next
  
  'obtain current setting from registry as to whether to save
  'a copy in sent (or not)
  bSaveInSent = GetSetting(Application.Name, _
                           "Setup", "SaveInSent", True)
  
  'Toggle the value of the current setting by reversing it
  bSaveInSent = Not (bSaveInSent)
  'and write this REVERSE value back to registry
  SaveSetting Application.Name, "Setup", "SaveInSent", bSaveInSent
  
  'If the new value is set to SAVE items in Sent Folder
  If bSaveInSent Then
    'Change the caption on the button to reflect that
    bButton.Caption = "InSent: YES"
  Else
    'Since new value is to NOT save the item "Sent Items" folder
    'change the button face accordingly
    bButton.Caption = "InSent: NO"
  End If
End Sub

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  'This subroutine runs every time a message is "sent" by Outlook
  '(when the "Send" button is clicked) and this code we have 
  'written overrides the default internal "ItemSend" routine normally
  'run by Outlook.

  'Our change routine makes a decision whether to save a "Sent: item 
  'in the "Sent" folder or not, based on the setting in the registry 
  '(and showing on the face of our button in the menu).
  
  Dim bSaveInSent As Boolean  'Holds current state of whether we want 
                              'to save or not (True/False)
   
  'ascertain current value from registry (the default = True)
  bSaveInSent = GetSetting(Application.Name, "Setup", _
                           "SaveInSent", True)
  
  'If the item IS to be saved
  If bSaveInSent Then
    'we will not delete it from our "Sent" records after it is 
    'submitted
    Item.DeleteAfterSubmit = False
  Else
    'otherwise, we DONT want save the item in the "Sent" Folder 
    'so we delete the message it after it has been submitted
    Item.DeleteAfterSubmit = True
  End If
End Sub

Open in new window

0
 
inforrAuthor Commented:
Wow craisin! I can't believe how much effort you have gone to. I will try this out and let you know!

Thank you once again!
0
 
inforrAuthor Commented:
Ok just tried it and I followed the steps to add it to the toolbar. The button is added but as soon as I click Close in Step 14 the button disappears from the toolbar.

Do you know why that happens?
0
 
David LeeCommented:
Very nice, Chris.
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
Are you still in the "New Message" dialogue? It did not diappear for me.

If you now click on "New Message" to create a new message, or "Respond"  to respond to an existing one, the button should appear. It will NOT appear in your main Outlook View, only on "Reply" or "New Message" dialogues.

It is STILL present on my system days after creation and I have decided to leave it there as a "feature" for my Outlook ..Thanks for the idea!   :-)

If the button was created correctly on your system, it should still appear in the list of controls in step 4 (get there by following steps 2,3 and 4 in sequence from a "New" or "Reply" Menu). Again I emphasize, it will only appear when you are is "Respond" or "New" mode in an email.

If you still cannot find it, you must have bypassed a step, so try it all again.
Looking forward to seeing how it goes.

By the way, this methodology applies to ANY macro you write and can be used for a standard method for adding macro buttons. (I think I might submit it as an article for EE)   :-)

Cheers  :-)
Chris (craisin)
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
Any progress in getting the button to stay in the menus of New/Reply emails?
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
Hello? Are there any developments? It is now March 13th and there has been no reply since early February!
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
Inforr......have you resolved your issue yet?
0
 
inforrAuthor Commented:
I made some progress recently as I saw that the toolbar button was getting added to the end which was why I didn't see it. I had to click the ">>" to see it. I haven't had a chance to play with it again since but hope to do so this week. Apologies for the delay!
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
Any success yet?
0
 
inforrConnect With a Mentor Author Commented:
1000 x apologies.

Finally got round to testing it out and it rocks.

Thanks again!
0
 
inforrAuthor Commented:
Craisin is amazin'
0
 
inforrAuthor Commented:
Hi Craisin,

I have one follow up request. Since using this macro, one thing I have found is that the setting is persistent which results in me forgetting I have turned off keeping sent mail. It would be great if every time I replied/created a new message it would default to ON.

Is that possible?

Thanks.
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
Sure thing! That of course means you really want it left on all the time, does it not?

Anyway....stand by.....
0
 
inforrAuthor Commented:
That's right - thanks
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
OK, I have changed the code slightly.

Please note that the macro called now is "ToggleSaveInSent" NOT
"ToggelSaveInSent" (typing error in last code). It will run automatically every tme an email is sent.

Now the code checks each email as it is sent, and sees whether the user has activated indocated that the email is to be stored in the SENT folder or not.
If so, no problems.

If the user has indicated that it NOT be stored in the SENT folder, the macro
will heck first to see whether a warning message is to be issued (the default is YES). If it is to issue a warning message, it asks whether the user wishes to start saving in the SENT folder.

If the user DOES so wish, no problems. The system starts saving, with no further messages.

If the user does NOT so wish, the macro then asks if further warning messages are to be displayed.

If these warning messages are not to be displayed any further, then the only way the user can get the macro to work again is to click the "SaveInSent" macro button to turn the saving on.

Of course, if the user elects to continue with the warning message, so be it.
The current message will NOT be stored in the SENT folder, and the warnings will continue with future messages as they are sent. (This could be annoying if there are hundreds of messages being sent of course).

Is this what you are after?

If you prefer no question being asked, and that the "SAVE IN SENT" is always YES, then of course a button would not really be required. The code would simply becomes the following five lines:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
   'This subroutine runs every time a message is "sent" and overrides the
   'default internal "ItemSend" routine normally runs by Outlook.
    Item.DeleteAfterSubmit = False
End Sub

I think it best to saty with the button, since other users of your machine (and you yourself) may sometimes wish that an item not be store in the SENT folder
(goodness knows why).

Is this what you are after?



Option Explicit
Public Sub ToggleSaveInSent()
  ' This subroutine simply toggles a value in the registry to record whether the current user
  ' wishes to store copies of sent items in the SENT folder or not, by use of a button on the
  ' Standard Menu in a NEW email message being created.
  
  Dim oBar As CommandBar                     'The "Standard" command bar in your Outlook message area
  Dim oControls As Office.CommandBarControls 'The controls (buttons etc.) on that command bar
  Dim x As Integer                           'Used to scan the controls to find our "InSent" button
  Dim bButton As CommandBarControl           'Our Button!
  Dim bSaveInSent As Boolean                 'Holds current state of whether we want to save or not (True/False)
  
  'gather data from our Standard toolbar
  Set oBar = Application.ActiveWindow.CommandBars("Standard")
  Set oControls = oBar.Controls

  'Find our button on the toolbar
  For x = 1 To oControls.Count
    'if the words "Insent:" appear somewhere on the control we are currently looking at,
    If InStr(oControls.Item(x).Caption, "InSent:") > 0 Then
      'then this is our button!
      Set bButton = oBar.Controls.Item(x)
      Exit For
    End If
  Next
  
  'obtain current setting from registry as to whether to save a copy in sent (or not)
  bSaveInSent = GetSetting(Application.Name, "Setup", "SaveInSent", True)
  
  'Toggle the value of the current setting by reversing it
  bSaveInSent = Not (bSaveInSent)
  'and write this REVERSE value back to registry
  SaveSetting Application.Name, "Setup", "SaveInSent", bSaveInSent
  
  'If the new value is set to SAVE items in Sent Folder
  If bSaveInSent Then
    'Change the caption on the button to reflect that
    bButton.Caption = "InSent: YES"
  Else
    'Since new value is to NOT save the item "Sent Items" folder
    'change the button face accordingly
    bButton.Caption = "InSent: NO"
  End If
End Sub
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  'This subroutine runs every time a message is "sent" and overrides the
  'default internal "ItemSend" routine normally runs by Outlook.
  'It makes a decision whether to save a sent item to the "Sent" folder or not.
  
  Dim bSaveInSent As Boolean  'Holds current state of whether we want to save or not (True/False)
   
  'ascertain current value from registry
  bSaveInSent = GetSetting(Application.Name, "Setup", "SaveInSent", True)
  
  'If the item IS to be saved
  If bSaveInSent Then
    'we will not delete it after it is sent
    Item.DeleteAfterSubmit = False
  Else
    If GetSetting(app.exename, "Setup", "SaveInSentWarning", "True") = "True" Then
      If MsgBox("Mail is currently set to NOT save in the " + Chr(34) + "Sent " + Chr(34) + "folder'" + vbCrLf + _
        "Do you wish to start saving to the SENT folder?", vbQuestion + vbYesNo, "SaveInSent") = vbNo Then
        'we DONT save the item in the "Sent" Folder by deleting it after it has been submitted
        Item.DeleteAfterSubmit = True
        If MsgBox("Do you want this warning message to happen each time?", vbQuestion + vbYesNo) = vbNo Then
          'store in the registry to tunr off the warning
          SaveSetting app.exename, "Setup", "SaveInSentWarning", "False"
        End If
      Else
        'turn on the systems setting to save email in the SENT folder
        SaveSetting app.exename, "Setup", "SaveInSent", "True"
        Item.DeleteAfterSubmit = True
      End If
    Else
      'No warning is to show.
      'To start saving in the SENT folder, the user must click the SAVEINSENT button
      'in the toolbar.
    End If
  End If
End Sub

Open in new window

0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
Please note that the above code is for use in Outlook 2003/2007 only.

Outlook 2010 changed the way it displays the menubars (went to ribbons) and it is much more complex (I'm working on it).

In the meantime, just test the above and advise if that is what you are after.

Many thanks

Chris
(craisin)
0
 
inforrAuthor Commented:
Hi Chris,

Thanks for making the changes.

I actually want it to be simpler. Basically using the original macro, I'd like to have it set so InSent always defaults to "InSent:YES" with each reply or new email. So if I select "InSent:NO" for one email, the next email I reply or send will have "InSent:YES" automatically. Does that make sense?

Is that possible? If not I can stick with the modified version.

Thanks.

0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
OK that is fine.

I will make the changes ASAP.


Stand by......
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
OK Inforr,

The changed code appears below.

The comments in the code should make it self explanatory.

Give it a go and let me know if that is what you are after.

Cheers
Chris
(craisin)
Option Explicit
Public Sub ToggleSaveInSent()
  ' This subroutine simply toggles a value in the registry to record whether the current user
  ' wishes to store copies of sent items in the SENT folder or not, by use of a button on the
  ' Standard Menu in a NEW email message being created.
  
  Dim oBar As CommandBar                     'The "Standard" command bar in your Outlook message area
  Dim oControls As Office.CommandBarControls 'The controls (buttons etc.) on that command bar
  Dim x As Integer                           'Used to scan the controls to find our "InSent" button
  Dim bButton As CommandBarControl           'Our Button!
  Dim bSaveInSent As Boolean                 'Holds current state of whether we want to save or not (True/False)
   
  'gather data from our Standard toolbar
  Set oBar = Application.ActiveWindow.CommandBars("Standard")
  Set oControls = oBar.Controls

  'Find our button on the toolbar
  For x = 1 To oControls.Count
    'if the words "Insent:" appear somewhere on the control we are currently looking at,
    If InStr(oControls.Item(x).Caption, "InSent:") > 0 Then
      'then this is our button!
      Set bButton = oBar.Controls.Item(x)
      Exit For
    End If
  Next
  
  'obtain current setting from registry as to whether to save a copy in sent (or not)
  bSaveInSent = GetSetting(Application.Name, "Setup", "SaveInSent", True)
  
  'Toggle the value of the current setting by reversing it
  bSaveInSent = Not (bSaveInSent)
  'and write this REVERSE value back to registry
  SaveSetting Application.Name, "Setup", "SaveInSent", bSaveInSent
  
  'If the new value is set to SAVE items in Sent Folder
  If bSaveInSent Then
    'Change the caption on the button to reflect that
    bButton.Caption = "InSent: YES"
  Else
    'Since new value is to NOT save the item "Sent Items" folder
    'change the button face accordingly
    bButton.Caption = "InSent: NO"
  End If
End Sub
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  'This subroutine runs every time a message is "sent" and overrides the
  'default internal "ItemSend" routine normally runs by Outlook.
  'It makes a decision whether to save a sent item to the "Sent" folder or not.
  
  Dim bSaveInSent As Boolean  'Holds current state of whether we want to save or not (True/False)
   
  'ascertain current value from registry
  bSaveInSent = GetSetting(Application.Name, "Setup", "SaveInSent", True)
  
  'If the item IS to be saved
  If bSaveInSent Then
    'we will not delete it after it is sent, so it will remain in the SENT folder
    Item.DeleteAfterSubmit = False
  Else
    'Tell Outlook to NOT save the item in SENT folder
    Item.DeleteAfterSubmit = True
    'then toggle the setting back ON to save future emails in SENT.....
    ToggleSaveInSent
  End If
End Sub

Open in new window

0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
I remind you though, if you change to Outlook in Office 2007 or later the button will not work as it does here (since 2007 and later use ribbons instead of normal toolbar). I am working on incorporating this into Outlook 2010, but it is hard gong (doing it just for the exercise)  :-)

The "macro" as such will still work, and so you would manually have to set up a button to run the macro "ToggleSaveInSent" (the code wont create the button at the moment). If you do go to a later version, make sure you include BOTH "ToggleSaveInSent" and the re-written "Application_ItemSend" code.

Looking forward to seeing how it goes for you  :-)

Cheers
Chris (craisin)
0
 
inforrAuthor Commented:
Just loaded it up now. So far so good. Will let you know when I've sent a few more emails. Having the Outlook 2010 version will be great as I will be moving to that later in the year. So your effort wouldn't be wasted.
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
The down-side was that while I was writing the original, I accidentally left "InSent:No" in effect on my PC (and outlook 2010 does not have a button showing yet so I did not know) Dozens of emails I sent out over a two week period had no copies retainined in my Outlook!

Some were quite important and so I feel a bit of a fool asking people to send me a copy of an email I sent them!  :-) (I blamed it on Microsoft! If you do that, people tend to not question it  LOL)

Hope it works for you...
Cheers
0
 
inforrAuthor Commented:
Oh man I'm sorry - feel guilty now. That's what was happening with me and hence the need for the automatic reset.
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
LOL...OK, well, just let me know it it all works OK now....

Chris
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.