RE: Button to put disclaimer on email.
- From: "Eric Legault [MVP - Outlook]" <elegaultZZZ@xxxxxxxxxxxxxxxxx>
- Date: Wed, 4 May 2005 19:51:16 -0700
If you want to install this on multiple machines, the best approach (but more
work and a little more involved) is to implement this as a COM Add-In.
However, after thinking about your intent, I believe it will be easier just
to manually create your custom button for the Inspector windows, and
associate it with a simple Sub procedure macro. This way, you don't have to
worry about trapping Inspectors and automatically creating the button. Just
call the ActiveInspector object in this procedure. It can be fired by
mapping your custom button to the procedure name in the menu customization
dialog.
If you want to customize Rich Text formatting in the message body, the only
way to do this is with Redemption's SafeInspector object
(http://www.dimastr.com). Otherwise, for HTML formatting you can use good
ol' HTML tags. Remember that the .Body or .HTMLBody properties are just one
big fat string. There's no "sequential" editing or anything fancy you can do
(like ReadLine, ReadAll, etc.).
--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/
"Tash" wrote:
> This is working out great. Now after the user clicks on this button. How can
> I access the email textarea of the current inspector. I need to put in a
> disclaimer. And is there a way to make it a certain font and/or bold as I am
> putting it in?
>
> Also, I noticed that since the button is temporary every time I start
> outlook I have to run the module. I need to have it load on my clients
> machine every time. I know you can make a COM object that will load this
> module at loadtime right? Or is it better to make it not a temporary button
> that way it stays?
>
> ------------------------------------------------------------
> Private Sub objMyCustomButton_Click(ByVal ctrl As Office.CommandBarButton,
> CancelDefault As Boolean)
> MsgBox "I've been Clicked!"
> End Sub
>
> Thanks.
>
>
>
>
>
> "Eric Legault [MVP - Outlook]" wrote:
>
> > Sorry - I deliberated changed the order of the code in my reply to illustrate
> > the easy stuff first. The caveat, of course, is that declaring the
> > myInspectorTrapper variable isn't going to work until the clsInspectorTrapper
> > object is available - thus you need to create the clsInspectorTrapper Class
> > Module first before you can actually compile the code. If you have that
> > class created and named as above, the referring variable should know it is
> > declared against a valid class object. Try compiling now that you have the
> > Class created.
> >
> > The display of Modules and Class Modules (and User Forms) in the Project
> > Explorer is irrelevant, whether they are grouped by type or if it is listed
> > in a flat display. The ThisOutlookSession is essentially the default Module,
> > which cannot be removed. The only difference is that it has an explicit bind
> > to the Application object, which you'll see in addition to (General) in the
> > combo box on the left side at the top of the editor. This box also lists any
> > other module level variables that are declared WithEvents (you'll see the
> > variables that you've declared in clsInspectorTrapper in there as well when
> > you view the code from that class).
> >
> > --
> > Eric Legault - B.A, MCP, MCSD, Outlook MVP
> > --------------------------------------------------
> > {Private e-mails ignored}
> > Job: http://www.imaginets.com
> > Blog: http://blogs.officezealot.com/legault/
> >
> > "Tash" wrote:
> >
> > > Im getting a variable not declared error in the module that I put the
> > > creation of the clsInspectorTrapper class. I wish I can send a screenshot. Is
> > > that possible?
> > >
> > > Ok I made a module that has the following code. I just right clicked on
> > > ThisOutlookSession and Insert and Module. It made it module 1. Note(for some
> > > reason it makes a Modules directory that is on the same level as Microsoft
> > > Outlook Objects which has ThisOutlookSession inside it. So I dont know if it
> > > is really making this module inside thisoutlooksession, but I guess thats not
> > > my biggest problem at this state.
> > >
> > > The smartcomplete seems to see the variable because it changes my casing on
> > > as im typing, but I get a variable. Is it possible for me to send you a
> > > screenshot somewhere????
> > > --------------------------------------------------------
> > > Option Explicit
> > > Dim myInspectorTrapper As clsInspectorTrapper
> > >
> > > Private Sub TestTheInspectorTrapper()
> > > Set myInspctorTrapper = New clsInspectorTrapper
> > > End Sub
> > >
> > > Private Sub FinishedWithTheInspectorWrapper()
> > > Set myInspectorTrapper = Nothing
> > > End Sub
> > > -------------------------------------------------------------
> > >
> > > *****THEN
> > > I make a class by doing the same. It made another folder called Class
> > > Modules and put in Class1 (which i renames to clsInspectorTrapper).
> > >
> > > With exactly what you had
> > > -----------------------------------------------------
> > > Option Explicit
> > > Dim WithEvents objInspector As Outlook.Inspectors
> > > Dim WithEvents objMyInspector As Outlook.Inspector
> > > Dim WithEvents objMyMailItem As Outlook.MailItem
> > > Dim WithEvents objMyCustomButton As Office.CommandBarButton
> > >
> > > Private Sub Class_Initialize()
> > > Set objInspector = Application.Inspectors
> > > End Sub
> > >
> > > Private Sub Class_Terminate()
> > > Set objInspectors = Nothing
> > > Set objMyMailItem = Nothing
> > > Set objMyCustomButton = Nothing
> > > End Sub
> > >
> > > Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
> > > 'This event fires every time an item or Window is opened in Outlook (for
> > > email, contacts,
> > > 'Tasks, etc.)
> > > If Inspector.CurrentItem.Class <> olMail Then
> > > 'Only handle MailItem Objects
> > > Exit Sub
> > >
> > >
> > > 'Set reference to the e-mail so that we can trap the Open event
> > > Set objMyMailItem = Inspector.CurrentItem
> > > Set objMyInspector = Inspector
> > >
> > > End Sub
> > >
> > > Private Sub objMyCustomButton_Click(ByVal ctrl As Office.CommandBarButton,
> > > CancelDefault As Boolean)
> > > MsgBox "I've been Clicked!"
> > > End Sub
> > >
> > > Private Sub objMyMailItem_Close(Cancel As Boolean)
> > > Set objMyMailItem = Nothing
> > > End Sub
> > >
> > > Private Sub objmymailitem_open(Cancel As Boolean)
> > > Dim objCommandBar As Office.CommandBar
> > > Set objCommandBar = objMyInspector.CommandBars("Standard")
> > > Set objCustomButtom = objCommandBar.Controls.Add(msoControlButton, , , , True)
> > > objMyCustomButton.Caption = "Circular 230"
> > > objMyCustomButton.Visible = True
> > > objCommandBar.Visible = True
> > > End Sub
> > > -------------------------------------------------------------------------
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > "Eric Legault [MVP - Outlook]" wrote:
> > >
> > > > Sorry, I wasn't very clear. I've got a better example. I'll start with the
> > > > code that will create a custom class called clsInspectorTrapper. Put this
> > > > anywhere you want (Module or Class; usually the ThisOutlookSession module),
> > > > as long as you have this in the General Declarations section:
> > > >
> > > > Option Explicit
> > > > Dim myInspectorTrapper As clsInspectorTrapper
> > > >
> > > > Now we have to create this class in a test procedure (or whatever procedure
> > > > you want):
> > > >
> > > > Sub TestTheInspectorTrapper()
> > > > Set myInspectorTrapper = New clsInspectorTrapper
> > > > 'Usually this should be called in the
> > > > ThisOutlookSession.Application_Startup() event.
> > > > End Sub
> > > >
> > > > Sub FinishedWithTheInspectorWrapper()
> > > > Set myInspectorTrapper = Nothing
> > > > End Sub
> > > >
> > > > Now create the class called clsInspectorTrapper and add the code below.
> > > > Note the comments. If you have any questions, let me know:
> > > >
> > > >
> > > > Option Explicit
> > > > Dim WithEvents objInspectors As Outlook.Inspectors
> > > > Dim WithEvents objMyInspector As Outlook.Inspector
> > > > Dim WithEvents objMyMailItem As Outlook.MailItem
> > > > Dim WithEvents objMyCustomButton As Office.CommandBarButton
> > > >
> > > > Private Sub Class_Initialize()
> > > > 'Return a handle to the Inspectors collection
> > > > Set objInspectors = Application.Inspectors
> > > > End Sub
> > > >
> > > > Private Sub Class_Terminate()
> > > > Set objInspectors = Nothing
> > > > Set objMyMailItem = Nothing
> > > > Set objMyCustomButton = Nothing
> > > > End Sub
> > > >
> > > > Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
> > > > 'This event will fire every time an item or Window is opened in Outlook
> > > > (for e-mail, Contacts, Tasks, etc.)
> > > >
> > > > If Inspector.CurrentItem.Class <> olMail Then
> > > > 'Only handle MailItem objects
> > > > Exit Sub
> > > > End If
> > > >
> > > > 'Set a reference to the e-mail so that we can trap the Open event
> > > > Set objMyMailItem = Inspector.CurrentItem
> > > > Set objMyInspector = Inspector
> > > > End Sub
> > > >
> > > > Private Sub objMyCustomButton_Click(ByVal Ctrl As Office.CommandBarButton,
> > > > CancelDefault As Boolean)
> > > > MsgBox "I've been clicked!"
> > > > End Sub
> > > >
> > > > Private Sub objMyMailItem_Close(Cancel As Boolean)
> > > > Set objMyMailItem = Nothing
> > > > End Sub
> > > >
> > > > Private Sub objMyMailItem_Open(Cancel As Boolean)
> > > > Dim objCommandBar As Office.CommandBar
> > > >
> > > > Set objCommandBar = objMyInspector.CommandBars("Standard")
> > > > Set objMyCustomButton = objCommandBar.Controls.Add(msoControlButton, , ,
> > > > , True) 'Set True for temporary buton
> > > > objMyCustomButton.Caption = "My custom button"
> > > > End Sub
> > > >
> > > >
> > > > --
> > > > Eric Legault - B.A, MCP, MCSD, Outlook MVP
> > > > --------------------------------------------------
> > > > {Private e-mails ignored}
> > > > Job: http://www.imaginets.com
> > > > Blog: http://blogs.officezealot.com/legault/
> > > >
> > > >
> > > >
> > > > "Tash" wrote:
> > > >
> > > > > I'm sorry, I'm a bit confused. This is what I was trying to make from your
> > > > > suggestion. I am doing this in Outlooks built in VBA. Before I had a module
> > > > > object and it didnt let me make the WithEvents so I made a class. But would I
> > > > > need a class declaration. I'm more famaliar with .NET. Please assume I dont
> > > > > know much of VBA because I dont. What does _Click() take in as parameters???
> > > > > ------------------------------------
> > > > >
> > > > > Dim WithEvents objCustomButton As Office.CommandBarButton
> > > > >
> > > > > Function CreateSampleToolbar() As Office.CommandBar
> > > > >
> > > > > Dim objApp As Outlook.Application
> > > > > Dim colCB As Office.CommandBars
> > > > > Dim objCB As Office.CommandBar
> > > > > Dim objControls As Office.CommandBarControls
> > > > > Dim objControl As Office.CommandBarControl
> > > > >
> > > > > Set objApp = CreateObject("Outlook.Application")
> > > > > Set colCB = objApp.ActiveInspector.CommandBars
> > > > > Set objCB = colCB.Add("Circular230", msoBarTop)
> > > > > Set objControls = objCB.Controls
> > > > >
> > > > > Set objCustomButton = objControl
> > > > > objControl.Caption = "Circular 230"
> > > > >
> > > > > objControl.Visible = True
> > > > > objCB.Visible = True
> > > > >
> > > > > Set CreateSampleToolbar = objCB
> > > > >
> > > > > Set sInspector = CreateObject("Redemption.SafeInspector")
> > > > > sInspector.Item = Application.ActiveInspector
> > > > > sInspector.SelText = "Testing circular 210"
> > > > > Set RTFEditor = sInspector.RTFEditor
> > > > > RTFEditor.SelAttributes.Style.Bold = True
> > > > >
> > > > >
> > > > > Set objCB = Nothing
> > > > > Set colCB = Nothing
> > > > > Set objApp = Nothing
> > > > >
> > > > > End Function
> > > > >
> > > > > Sub objCustomButton_Click()
> > > > >
> > > > > End Sub
> > > > >
> > > > >
> > > > >
> > > > > ------------------------------------
> > > > >
> > > > > "Eric Legault [MVP - Outlook]" wrote:
> > > > >
> > > > > > All you need to do is add this to the General Declarations section for that
> > > > > > module:
> > > > > >
> > > > > > Dim WithEvents objCustomButton As Office.CommandBarButton
> > > > > >
> > > > > > Then in your Function, add:
> > > > > >
> > > > > > Set objCustomButton = objControl
> > > > > >
> > > > > > Now you can handle the objCustomButton_Click event, where you can get a
> > > > > > MailItem object from the ActiveInspector.CurrentItem property, and access
> > > > > > MailItem.Body to get/set the message text.
> > > > > >
> > > > > > --
> > > > > > Eric Legault - B.A, MCP, MCSD, Outlook MVP
> > > > > > --------------------------------------------------
> > > > > > {Private e-mails ignored}
.
- Follow-Ups:
- RE: Button to put disclaimer on email.
- From: Tash
- RE: Button to put disclaimer on email.
- References:
- RE: Button to put disclaimer on email.
- From: Tash
- RE: Button to put disclaimer on email.
- From: Eric Legault [MVP - Outlook]
- RE: Button to put disclaimer on email.
- From: Tash
- RE: Button to put disclaimer on email.
- From: Eric Legault [MVP - Outlook]
- RE: Button to put disclaimer on email.
- From: Tash
- RE: Button to put disclaimer on email.
- From: Eric Legault [MVP - Outlook]
- RE: Button to put disclaimer on email.
- From: Tash
- RE: Button to put disclaimer on email.
- Prev by Date: Re: Open User Form from Template and populate message
- Next by Date: How can I customise a contacts list in Outlook?
- Previous by thread: RE: Button to put disclaimer on email.
- Next by thread: RE: Button to put disclaimer on email.
- Index(es):