Solved

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

Posted on 2011-02-24
34
537 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:inforr
  • 20
  • 11
  • 3
34 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 34972161
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
 

Author Comment

by:inforr
ID: 34972350
Hi BlueDevilFan,

Yep that would work.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 34972519
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
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 34982970
I am writing a bit of code for you now to toggle a button as requested - please give me 20 minutes.
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 34983563
Taking a bit longer than I thought.....stand by
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 34984863
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
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 34984869
OOps...forget that last question....I just realised which option you are talking about....

Please stand by
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 34985345
Success!  Now just give me a moment to upload everything.
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 34985557
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
 
LVL 13

Accepted Solution

by:
Chris Raisin earned 500 total points
ID: 34985834
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
 

Author Comment

by:inforr
ID: 35003121
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
 

Author Comment

by:inforr
ID: 35003149
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
 
LVL 76

Expert Comment

by:David Lee
ID: 35003153
Very nice, Chris.
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 35004031
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
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 35016281
Any progress in getting the button to stay in the menus of New/Reply emails?
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 35115867
Hello? Are there any developments? It is now March 13th and there has been no reply since early February!
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 35142357
Inforr......have you resolved your issue yet?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:inforr
ID: 35143998
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
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 35281761
Any success yet?
0
 

Assisted Solution

by:inforr
inforr earned 0 total points
ID: 35311117
1000 x apologies.

Finally got round to testing it out and it rocks.

Thanks again!
0
 

Author Closing Comment

by:inforr
ID: 35349343
Craisin is amazin'
0
 

Author Comment

by:inforr
ID: 35400821
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
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 35400949
Sure thing! That of course means you really want it left on all the time, does it not?

Anyway....stand by.....
0
 

Author Comment

by:inforr
ID: 35404796
That's right - thanks
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 35405037
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
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 35405582
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
 

Author Comment

by:inforr
ID: 35412184
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
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 35413205
OK that is fine.

I will make the changes ASAP.


Stand by......
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 35423368
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
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 35423422
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
 

Author Comment

by:inforr
ID: 35424953
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
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 35425638
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
 

Author Comment

by:inforr
ID: 35425968
Oh man I'm sorry - feel guilty now. That's what was happening with me and hence the need for the automatic reset.
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 35426116
LOL...OK, well, just let me know it it all works OK now....

Chris
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Learn more about how the humble email signature can be used as more than just an electronic business card. When used correctly, a signature can easily be tailored for different purposes by different departments within an organization.
Find out how to use dynamic social media in email signatures with this top 10 DOs & DON’Ts.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now