Outlook 2003 - Send & File command button

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In Outlook 2003--

I need to have a command for me to SEND email and then prompt me to FILE the
sent email into one of my folders that I choose so I am able to pick the
folder each time.

I would like to create a button in the standard menu bar for: Send & File

Thank you
 
Try this code. Just paste into your ThisOutlookSession module, and run the
Application_Startup procedure to set it up.

Option Explicit
Dim objNS As Outlook.NameSpace
Dim WithEvents objMailItem As Outlook.MailItem
Dim WithEvents objInsp As Outlook.Inspector
Dim WithEvents objInsps As Outlook.Inspectors
Dim WithEvents objCBB As Office.CommandBarButton

Private Sub Application_Startup()
Set objNS = Application.GetNamespace("MAPI")
Set objInsps = Application.Inspectors
End Sub

Private Sub Application_Quit()
Set objNS = Nothing
Set objInsps = Nothing
End Sub

Private Sub objInsps_NewInspector(ByVal Inspector As Inspector)
If Inspector.CurrentItem.Class <> olMail Then Exit Sub

Set objInsp = Inspector
Set objMailItem = Inspector.CurrentItem
End Sub

Private Sub objInsp_Close()
Set objMailItem = Nothing
Set objCBB = Nothing
Set objInsp = Nothing
End Sub

Private Sub objMailItem_Open(Cancel As Boolean)
On Error Resume Next

Dim objCB As Office.CommandBar

'Build custom button
Set objCB = objInsp.CommandBars("Standard")

Set objCBB = objCB.Controls.Add(MsoControlType.msoControlButton, , , 3,
True)
objCBB.Caption = "Send and File..."
objCBB.Visible = True
Set objCB = Nothing
End Sub

Private Sub objCBB_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
On Error Resume Next

Dim objFolder As Outlook.MAPIFolder

Set objFolder = objNS.PickFolder

If objFolder Is Nothing Then Exit Sub
If objFolder.DefaultItemType <> olMailItem Then Exit Sub

Set objMailItem.SaveSentMessageFolder = objFolder
objMailItem.Send

Set objFolder = Nothing
End Sub
 
Eric (or any other Outlook guru),

I don't know if you remember this excellent reply you gave to jc1148
several months ago. My question is quite related: is it possible, upon
clicking Send, to have outlook prompt for CATEGORIES to assign the sent
e-mail (even better if it only prompts where no categories have been
assigned). The relevant window is what would you see after clicking
Options/Categories.

I'm asking this, in the hopes that something similar to your folders scripts
exists out there. Assigning categories and sorting by folders accomplish the
same ends, but in the gmail world it seems to me that categories is the
better way to go.

Thanks very much,
ckp
 
Thanks for your speedy reply, and sorry to be so daft, but I don't see where
in your sample VBA script I would add/replace with Item.ShowCategoriesDialog.
I'm only semi-literate with VBA scripts, but I excel at strategic cutting &
pasting. Best, Chet
 
Final annoying question:
Does this VBA script run before or after outlook runs its rules?
(in the most ideal world, some sent e-mail would be allocated categories
by these rules, and only failing that would the e-mails still without
categories prompt the sender to fill in a category).
Thanks so much. I promise to ask nothing further, although Outlook is full
of wonders and mysteries :)
 
First off, I didn't write that code you were referring to in the previous
post (Outlookcode.com is run by Sue Mosher).

The ShowCategoriesDialog is a method available to any Outlook object. So if
you have a MailItem object variable declared as objMyMessage, just call
objMyMessage.ShowCategoriesDialog. The user can then choose the Categories
and they will be saved with the item.

I'm still not quite sure how you are planning on using this, so your
question about the Rules Wizard is throwing me off. If you call
ShowCategoriesDialog before the message is sent, if you have any rules that
modify categories then they will still run.

If you know what values to add or remove from the Categories for a
particular item, simply set objMyMessage.Categories = "Category 1, Category
2" (etc.).
 
I'm still not quite sure how you are planning on using this, so your
question about the Rules Wizard is throwing me off.

Very sorry to be unclear. In my ideal world,
(i) some messages already have categories allocated (because they are
replies to a categorized e-mail)
(ii) after clicking send, my sent-mail rules will apply categories to some
e-mail
(iii) if, after all of this, the send-mail *still* has no categories
allocated, the "ShowCategoriesDialog" box will appear.
(iv) after all this, a copy of the categorized sent mail gets filed in a
folder (perhaps based on further rules, perhaps always to the same folder).

((second-best solution: even if the 'allocated category' dialogue always
appeared after clicking send, even if it already has a category, and even
before any of the rules run, this would be still a big improvement.))


I don't see objMyMessage used in your earlier script at the start of your
thread.

Thanks again for your replies.
ckp
 
Dare I also ask:

What would be the VBA call or script to have the user choose via which
ACCOUNT the message should be sent upon clicking send ("Accounts" on the
Message form).
(even better if this would only be asked if the user hasn't already selected
an account before clicking send).

many thanks,
chet
 
If you need the Categories dialog to automatically appear when the user
clicks the Send button, you need to do something like this:

Private Sub objMailItem_Send(Cancel As Boolean)
If objMailItem.Categories = "" Then
'Prompt for Categories
objMailItem.ShowCategoriesDialog
objMailItem.Save
End If
End Sub

To do this though, you have to set a reference to the Inspectors collection
when Outlook starts, and every time a new e-mail is created you need to get a
handle to the Inspector and MailItem object. I've got an article on my blog
that explains how to do this:

Getting a Handle on Your E-mails with VBA:
http://blogs.officezealot.com/legault/articles/2224.aspx

It's usually best to design this as a COM Add-In rather than macros in your
VBA Project, because they are easier to distribute and install for multiple
users. This link has good info on COM Add-Ins:

Developing COM Add-ins for Microsoft Outlook:
http://www.outlookcode.com/d/comaddins.htm

As for choosing the e-mail account to send the message with, there is no
point checking to see if an account hasn't been chosen because the default
account is always used if no other account is selected. The only way to
programmatically set the sending account is to get a reference to the menu
item and call it's Execute method (however, you need to know the name or
ordinal position of the account name in the menu):

Sub ChangeSendingAccount()
Dim objCBPU As Office.CommandBarPopup
Dim objCBB As Office.CommandBarButton

Set objCBPU = ActiveInspector.CommandBars.FindControl(, 31224) 'get
Accounts button on Standard toolbar

'Get menu item by name or index number
Set objCBB = objCBPU.Controls.Item("&1 Microsoft Exchange Server")
'Set objCBB = objCBPU.Controls.Item(2)

objCBB.Execute

Set objCBPU = Nothing
Set objCBB = Nothing
End Sub
 
Back
Top