Group:  Microsoft Outlook » microsoft.public.outlook.program_addins
Thread: access to and subject of a wordmail item

Geek News

access to and subject of a wordmail item
"forums[ at ]webgremlins.net" <forums[ at ]webgremlins.net> 2/20/2007 4:56:50 PM
hi there

I have managed to add some controls to the wordmail screen when word
is used sas the editor. This works all nice and dandy.

The problem is, is that i do not know how to access the to, subject
and other fields withing the mail

using outlook at the editor, i can do objmailitem.to = "" etc, to
reference the information, btu it doesnt work whe word is the editor

any ideas?

many thanks

Jamie

Re: access to and subject of a wordmail item
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 2/20/2007 7:35:54 PM
Show your code. A MailItem has valid subject and other properties whether or
not it's being shown in an Outlook editor window or a WordMail window.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


<forums[ at ]webgremlins.net> wrote in message
news:1171990610.483685.221470[ at ]a75g2000cwd.googlegroups.com...
[Quoted Text]
> hi there
>
> I have managed to add some controls to the wordmail screen when word
> is used sas the editor. This works all nice and dandy.
>
> The problem is, is that i do not know how to access the to, subject
> and other fields withing the mail
>
> using outlook at the editor, i can do objmailitem.to = "" etc, to
> reference the information, btu it doesnt work whe word is the editor
>
> any ideas?
>
> many thanks
>
> Jamie
>

Re: access to and subject of a wordmail item
"forums[ at ]webgremlins.net" <forums[ at ]webgremlins.net> 2/23/2007 4:40:17 PM
before i go through and post my code, (i have to strip alot out)

i am able to access the attachments array ok
I can set the to and subject properties programmatically, by doinng
ObjMailitem.to = "mail[ at ]domain.com", i can slo set the subject too

But, when i click my custom control and check objmailitem.to, it is
nothing, empty!

i added the following ot control and clicked it

objmailitem.to = "j[ at ]ddd.com"
objmailitem.subject = "tester"

The fields int he email are updated with this information, then when i
click my send custom control and check the fields, these values are
displayed, even if i add extra info to the fields.

Very wierd any clues? if not, i will post my code. this is only
apparent when using word as editor, all works fine when using
outlook.

cheers

Jamie


Re: access to and subject of a wordmail item
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 2/26/2007 4:31:05 PM
Are you saving the item after you set properties on the WordMail item?

Other than that I can't think of anything offhand, if you can't get
Inspector.CurrentItem.Subject after the first Inspector.Activate event has
fired then something is definitely wrong.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


<forums[ at ]webgremlins.net> wrote in message
news:1172248817.463794.267310[ at ]z35g2000cwz.googlegroups.com...
[Quoted Text]
> before i go through and post my code, (i have to strip alot out)
>
> i am able to access the attachments array ok
> I can set the to and subject properties programmatically, by doinng
> ObjMailitem.to = "mail[ at ]domain.com", i can slo set the subject too
>
> But, when i click my custom control and check objmailitem.to, it is
> nothing, empty!
>
> i added the following ot control and clicked it
>
> objmailitem.to = "j[ at ]ddd.com"
> objmailitem.subject = "tester"
>
> The fields int he email are updated with this information, then when i
> click my send custom control and check the fields, these values are
> displayed, even if i add extra info to the fields.
>
> Very wierd any clues? if not, i will post my code. this is only
> apparent when using word as editor, all works fine when using
> outlook.
>
> cheers
>
> Jamie
>
>

Re: access to and subject of a wordmail item
"forums[ at ]webgremlins.net" <forums[ at ]webgremlins.net> 2/27/2007 2:04:19 PM
On 26 Feb, 16:31, "Ken Slovak - [MVP - Outlook]" <kenslo...[ at ]mvps.org>
wrote:
[Quoted Text]
> Are you saving the item after you set properties on the WordMail item?
>
> Other than that I can't think of anything offhand, if you can't get
> Inspector.CurrentItem.Subject after the first Inspector.Activate event has
> fired then something is definitely wrong.
>
> --
> Ken Slovak
> [MVP - Outlook]http://www.slovaktech.com
> Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
> Reminder Manager, Extended Reminders, Attachment Optionshttp://www.slovaktech.com/products.htm
>
> <for...[ at ]webgremlins.net> wrote in message
>
> news:1172248817.463794.267310[ at ]z35g2000cwz.googlegroups.com...
>
>
>
> > before i go through and post my code, (i have to strip alot out)
>
> > i am able to access the attachments array ok
> > I can set the to and subject properties programmatically, by doinng
> > ObjMailitem.to = "m...[ at ]domain.com", i can slo set the subject too
>
> > But, when i click my custom control and check objmailitem.to, it is
> > nothing, empty!
>
> > i added the following ot control and clicked it
>
> > objmailitem.to = "j...[ at ]ddd.com"
> > objmailitem.subject = "tester"
>
> > The fields int he email are updated with this information, then when i
> > click my send custom control and check the fields, these values are
> > displayed, even if i add extra info to the fields.
>
> > Very wierd any clues? if not, i will post my code. this is only
> > apparent when using word as editor, all works fine when using
> > outlook.
>
> > cheers
>
> > Jamie- Hide quoted text -
>
> - Show quoted text -

Hi Ken

Thankyou for the reply. I have gone trhough and stripped my code down.
I do hope it is a simple error!

I have this class calld OutAddIn

Option Explicit
'Object variables for Event procedures
Private WithEvents objOutlook As Outlook.Application
Private WithEvents objWord As Word.Application
Private WithEvents objNS As Outlook.NameSpace
Private WithEvents objExpl As Outlook.Explorer
Private WithEvents colExpl As Outlook.Explorers
Private WithEvents objInsp As Outlook.Inspector
Private WithEvents colInsp As Outlook.Inspectors
Private WithEvents objMailItem As Outlook.MailItem
Private WithEvents objPostItem As Outlook.PostItem
Private WithEvents objContactItem As Outlook.ContactItem
Private WithEvents objDistListItem As Outlook.DistListItem
Private WithEvents objApptItem As Outlook.AppointmentItem
Private WithEvents objTaskItem As Outlook.TaskItem
Private WithEvents objJournalItem As Outlook.JournalItem
Private WithEvents objDocumentItem As Outlook.DocumentItem

'******************************************************************************
'These event-aware objects are for Outlook 2002 only
'Uncomment to use in Outlook 2002 COM Add-in
'Private WithEvents colViews As Outlook.Views
'Private WithEvents objResults As Outlook.Results
'Private WithEvents colReminders As Outlook.Reminders
'******************************************************************************
'Declare CommandBar, CommandBarButton, and CommandBarComboBox object
variables here
'Don't use WithEvents for CommandBar object
'Remove comments to declare object variables for CommandBar objects
'Dim objCB As Office.CommandBar
'Dim WithEvents objCBButton As Office.CommandBarButton
'Dim WithEvents objCBComboBox As Office.CommandBarComboBox
oSendLogMenuBar
Dim objCBars As Office.CommandBars
Dim objCB As Office.CommandBar
Dim oMyControl As Office.CommandBarPopup
Dim bar As Office.CommandBar

Dim WithEvents oSealandSendMenuBar As Office.CommandBarButton
Dim WithEvents oVerifyMenuBar As Office.CommandBarButton
Dim WithEvents oVerifyExternalMenuBar As Office.CommandBarButton
Dim WithEvents oExtractMenuBar As Office.CommandBarButton
Dim WithEvents oAboutMenuBar As Office.CommandBarButton
Dim WithEvents oHelpMenuBar As Office.CommandBarButton
Dim WithEvents oSendLogMenuBar As Office.CommandBarButton
Dim WithEvents oWordSealandSendMenuBar As Office.CommandBarButton



Dim WithEvents oSealandSendToolBar As Office.CommandBarButton
Dim WithEvents oVerifyToolBar As Office.CommandBarButton
Dim WithEvents oExtractToolBar As Office.CommandBarButton
'Dim WithEvents oTitleToolBar As Office.CommandBarButton
'Dim WithEvents oValidateExternalToolBar As Office.CommandBarButton

'controls for new inspector objects
Dim WithEvents oSealandSendNew As Office.CommandBarButton
Dim WithEvents oSealAttachmentNew As Office.CommandBarButton
Dim WithEvents oSealAllAttachmentsNew As Office.CommandBarButton
Dim WithEvents oVerifyNew As Office.CommandBarButton
Dim WithEvents oExtractNew As Office.CommandBarButton

Dim ShowSealAndSendControl As Boolean
Dim OutlookVersion As String


Private Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As
String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal
nShowCmd As Long) As Long


'******************************************************************************

'******************************************************************************
'Custom procedure: InitHandler(olApp As Outlook.Application, strProgID
As String)
'Purpose: Initialize event-aware object variables
'******************************************************************************
Friend Sub InitHandler(olApp As Outlook.Application, strProgID As
String)

'On Error Resume Next

Set objOutlook = olApp 'Application Object

'Instantiate a public module-level Outlook application variable
Set m_olApp = olApp
'CDO Session if required
'Uncomment for CDO
'Set m_objCDO = CreateObject("MAPI.Session")
'm_objCDO.Logon "", "", False, False
'Declared WithEvents
Set objNS = objOutlook.GetNamespace("MAPI") 'NameSpace Object
'Uncomment to use in Outlook 2002 COM Add-in
'Set colReminders = objOutlook.Reminders 'Reminders Object
Set colExpl = objOutlook.Explorers 'Explorers Object
Set colInsp = objOutlook.Inspectors 'Inspectors Object
Set objExpl = objOutlook.ActiveExplorer 'Explorer Object


End Sub

'detect the type, then bind the new inspector item to ObjMailitem
Private Sub colInsp_NewInspector(ByVal Inspector As Inspector)

Dim objItem As Outlook.MailItem

Set objInsp = Inspector
objInsp.Activate
Set objItem = objInsp.CurrentItem
Select Case objItem.Class
Case olMail
Set objMailItem = objItem
End Select

Set objItem = Nothing
End Sub

Private Sub objMailItem_Open(Cancel As Boolean)
Call addControls
End Sub

Private Sub addControls()

Dim cmdBar As Office.CommandBar
Dim cmdBars As Office.CommandBars
Set cmdBars = objMailItem.GetInspector.CommandBars

On Error Resume Next
Dim deletebar As Office.CommandBar
Set deletebar = cmdBars.Item("bar")
deletebar.Delete
deletebar = Nothing
On Error GoTo 0

Set cmdBar = cmdBars.Add("bar", 1, False, True)

Set oSealAllAttachmentsNew =
cmdBar.Controls.Add(Type:=msoControlButton, Temporary:=True)
oSealAllAttachmentsNew.Caption = "TruSeal &All Attachments"
oSealAllAttachmentsNew.ToolTipText = "Click here to Seal the
attachments on this email"
oSealAllAttachmentsNew.Tag = "oSealAllAttachmentsNew"
oSealAllAttachmentsNew.Style = msoButtonCaption
oSealAllAttachmentsNew.Visible = True

cmdBar.Visible = True


End Sub


'when i detect here the to value, it doesnt show anything.
Private Sub oSealAllAttachmentsNew_click(ByVal Ctrl As
Office.CommandBarButton, CancelDefault As Boolean)
MsgBox objInsp.CurrentItem.To
End Sub


This is my designers connect class

Option Explicit
'Use Implements IDTExtensibility2 in VB5 environment
'Implements IDTExtensibility2
Private gBaseClass As New OutAddIn

Private Sub AddinInstance_OnAddInsUpdate(custom() As Variant)
'DebugWrite "AddinInstance_OnAddInsUpdate"
End Sub

Private Sub AddinInstance_OnBeginShutdown(custom() As Variant)
'DebugWrite "AddinInstance_OnBeginShutdown"
End Sub

Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)

'On Error Resume Next
'Evaluate ConnectMode
Select Case ConnectMode
Case ext_cm_Startup
Case ext_cm_AfterStartup
Case ext_cm_CommandLine
Case ext_cm_Startup
End Select
'Don't call InitHandler if Explorers.Count = 0 and
Inspectors.Count = 0
If Application.Explorers.count = 0 And
Application.Inspectors.count = 0 Then
Exit Sub
End If

'AddInInst represents COMAddIn object
'Create and Initialize a base class
gBaseClass.InitHandler Application, AddInInst.ProgId
'DebugWrite "IDT2 OnConnection"

End Sub

Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode _
As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
'Tear down the class
'IMPORTANT: This event will not fire when
'RemoveMode = ext_dm_HostShutdown
'It will fire when RemoveMode = ext_dm_UserClosed


'gBaseClass.UnInitHandler
If RemoveMode = ext_dm_UserClosed Then
'User shutdown removed COM Add-in
'Cleanup custom toolbars by deleting them
Else
'Host shutdown
End If
Set gBaseClass = Nothing
If Constants.DEBUG_MODE = True Then
DEBUG_FILE.Write "AddinInstance_OnDisconnection: completed" &
" " & Time & vbCrLf
End If
'DebugWrite "AddinInstance_OnDisconnection"
End Sub

Private Sub AddinInstance_OnStartupComplete(custom() As Variant)
'
'DebugWrite "AddinInstance OnStartupComplete"
End Sub



Re: access to and subject of a wordmail item
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 2/27/2007 3:29:40 PM
It looks like a relatively standard implementation of the ItemsCB VB6
template.

Don't do anything in NewInspector other than instantiating your Inspector
class or event handler. Never call Inspector.Activate in that event. Wait
for the first Inspector.Activate event to fire before adding your UI and
doing anything else with that Inspector. In NewInspector you're given what's
known as a "weak" object reference, where not all properties of the
Inspector or Inspector.CurrentItem are populated. In NewInspector you really
shouldn't be doing much else than checking for Inspector.CurrentItem.Class
or Inspector.CurrentItem.MessageClass and then instantiating your Inspector
handler or wrapper class.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


<forums[ at ]webgremlins.net> wrote in message
news:1172585059.710141.158000[ at ]k78g2000cwa.googlegroups.com...
<snip>
[Quoted Text]
> Hi Ken
>
> Thankyou for the reply. I have gone trhough and stripped my code down.
> I do hope it is a simple error!
>
> I have this class calld OutAddIn
>
> Option Explicit
> 'Object variables for Event procedures
> Private WithEvents objOutlook As Outlook.Application
> Private WithEvents objWord As Word.Application
> Private WithEvents objNS As Outlook.NameSpace
> Private WithEvents objExpl As Outlook.Explorer
> Private WithEvents colExpl As Outlook.Explorers
> Private WithEvents objInsp As Outlook.Inspector
> Private WithEvents colInsp As Outlook.Inspectors
> Private WithEvents objMailItem As Outlook.MailItem
> Private WithEvents objPostItem As Outlook.PostItem
> Private WithEvents objContactItem As Outlook.ContactItem
> Private WithEvents objDistListItem As Outlook.DistListItem
> Private WithEvents objApptItem As Outlook.AppointmentItem
> Private WithEvents objTaskItem As Outlook.TaskItem
> Private WithEvents objJournalItem As Outlook.JournalItem
> Private WithEvents objDocumentItem As Outlook.DocumentItem
>
> '******************************************************************************
> 'These event-aware objects are for Outlook 2002 only
> 'Uncomment to use in Outlook 2002 COM Add-in
> 'Private WithEvents colViews As Outlook.Views
> 'Private WithEvents objResults As Outlook.Results
> 'Private WithEvents colReminders As Outlook.Reminders
> '******************************************************************************
> 'Declare CommandBar, CommandBarButton, and CommandBarComboBox object
> variables here
> 'Don't use WithEvents for CommandBar object
> 'Remove comments to declare object variables for CommandBar objects
> 'Dim objCB As Office.CommandBar
> 'Dim WithEvents objCBButton As Office.CommandBarButton
> 'Dim WithEvents objCBComboBox As Office.CommandBarComboBox
> oSendLogMenuBar
> Dim objCBars As Office.CommandBars
> Dim objCB As Office.CommandBar
> Dim oMyControl As Office.CommandBarPopup
> Dim bar As Office.CommandBar
>
> Dim WithEvents oSealandSendMenuBar As Office.CommandBarButton
> Dim WithEvents oVerifyMenuBar As Office.CommandBarButton
> Dim WithEvents oVerifyExternalMenuBar As Office.CommandBarButton
> Dim WithEvents oExtractMenuBar As Office.CommandBarButton
> Dim WithEvents oAboutMenuBar As Office.CommandBarButton
> Dim WithEvents oHelpMenuBar As Office.CommandBarButton
> Dim WithEvents oSendLogMenuBar As Office.CommandBarButton
> Dim WithEvents oWordSealandSendMenuBar As Office.CommandBarButton
>
>
>
> Dim WithEvents oSealandSendToolBar As Office.CommandBarButton
> Dim WithEvents oVerifyToolBar As Office.CommandBarButton
> Dim WithEvents oExtractToolBar As Office.CommandBarButton
> 'Dim WithEvents oTitleToolBar As Office.CommandBarButton
> 'Dim WithEvents oValidateExternalToolBar As Office.CommandBarButton
>
> 'controls for new inspector objects
> Dim WithEvents oSealandSendNew As Office.CommandBarButton
> Dim WithEvents oSealAttachmentNew As Office.CommandBarButton
> Dim WithEvents oSealAllAttachmentsNew As Office.CommandBarButton
> Dim WithEvents oVerifyNew As Office.CommandBarButton
> Dim WithEvents oExtractNew As Office.CommandBarButton
>
> Dim ShowSealAndSendControl As Boolean
> Dim OutlookVersion As String
>
>
> Private Declare Function ShellExecute Lib "shell32.dll" Alias
> "ShellExecuteA" _
> (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As
> String, _
> ByVal lpParameters As String, ByVal lpDirectory As String, ByVal
> nShowCmd As Long) As Long
>
>
> '******************************************************************************
>
> '******************************************************************************
> 'Custom procedure: InitHandler(olApp As Outlook.Application, strProgID
> As String)
> 'Purpose: Initialize event-aware object variables
> '******************************************************************************
> Friend Sub InitHandler(olApp As Outlook.Application, strProgID As
> String)
>
> 'On Error Resume Next
>
> Set objOutlook = olApp 'Application Object
>
> 'Instantiate a public module-level Outlook application variable
> Set m_olApp = olApp
> 'CDO Session if required
> 'Uncomment for CDO
> 'Set m_objCDO = CreateObject("MAPI.Session")
> 'm_objCDO.Logon "", "", False, False
> 'Declared WithEvents
> Set objNS = objOutlook.GetNamespace("MAPI") 'NameSpace Object
> 'Uncomment to use in Outlook 2002 COM Add-in
> 'Set colReminders = objOutlook.Reminders 'Reminders Object
> Set colExpl = objOutlook.Explorers 'Explorers Object
> Set colInsp = objOutlook.Inspectors 'Inspectors Object
> Set objExpl = objOutlook.ActiveExplorer 'Explorer Object
>
>
> End Sub
>
> 'detect the type, then bind the new inspector item to ObjMailitem
> Private Sub colInsp_NewInspector(ByVal Inspector As Inspector)
>
> Dim objItem As Outlook.MailItem
>
> Set objInsp = Inspector
> objInsp.Activate
> Set objItem = objInsp.CurrentItem
> Select Case objItem.Class
> Case olMail
> Set objMailItem = objItem
> End Select
>
> Set objItem = Nothing
> End Sub
>
> Private Sub objMailItem_Open(Cancel As Boolean)
> Call addControls
> End Sub
>
> Private Sub addControls()
>
> Dim cmdBar As Office.CommandBar
> Dim cmdBars As Office.CommandBars
> Set cmdBars = objMailItem.GetInspector.CommandBars
>
> On Error Resume Next
> Dim deletebar As Office.CommandBar
> Set deletebar = cmdBars.Item("bar")
> deletebar.Delete
> deletebar = Nothing
> On Error GoTo 0
>
> Set cmdBar = cmdBars.Add("bar", 1, False, True)
>
> Set oSealAllAttachmentsNew =
> cmdBar.Controls.Add(Type:=msoControlButton, Temporary:=True)
> oSealAllAttachmentsNew.Caption = "TruSeal &All Attachments"
> oSealAllAttachmentsNew.ToolTipText = "Click here to Seal the
> attachments on this email"
> oSealAllAttachmentsNew.Tag = "oSealAllAttachmentsNew"
> oSealAllAttachmentsNew.Style = msoButtonCaption
> oSealAllAttachmentsNew.Visible = True
>
> cmdBar.Visible = True
>
>
> End Sub
>
>
> 'when i detect here the to value, it doesnt show anything.
> Private Sub oSealAllAttachmentsNew_click(ByVal Ctrl As
> Office.CommandBarButton, CancelDefault As Boolean)
> MsgBox objInsp.CurrentItem.To
> End Sub
>
>
> This is my designers connect class
>
> Option Explicit
> 'Use Implements IDTExtensibility2 in VB5 environment
> 'Implements IDTExtensibility2
> Private gBaseClass As New OutAddIn
>
> Private Sub AddinInstance_OnAddInsUpdate(custom() As Variant)
> 'DebugWrite "AddinInstance_OnAddInsUpdate"
> End Sub
>
> Private Sub AddinInstance_OnBeginShutdown(custom() As Variant)
> 'DebugWrite "AddinInstance_OnBeginShutdown"
> End Sub
>
> Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
> ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
> ByVal AddInInst As Object, custom() As Variant)
>
> 'On Error Resume Next
> 'Evaluate ConnectMode
> Select Case ConnectMode
> Case ext_cm_Startup
> Case ext_cm_AfterStartup
> Case ext_cm_CommandLine
> Case ext_cm_Startup
> End Select
> 'Don't call InitHandler if Explorers.Count = 0 and
> Inspectors.Count = 0
> If Application.Explorers.count = 0 And
> Application.Inspectors.count = 0 Then
> Exit Sub
> End If
>
> 'AddInInst represents COMAddIn object
> 'Create and Initialize a base class
> gBaseClass.InitHandler Application, AddInInst.ProgId
> 'DebugWrite "IDT2 OnConnection"
>
> End Sub
>
> Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode _
> As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
> 'Tear down the class
> 'IMPORTANT: This event will not fire when
> 'RemoveMode = ext_dm_HostShutdown
> 'It will fire when RemoveMode = ext_dm_UserClosed
>
>
> 'gBaseClass.UnInitHandler
> If RemoveMode = ext_dm_UserClosed Then
> 'User shutdown removed COM Add-in
> 'Cleanup custom toolbars by deleting them
> Else
> 'Host shutdown
> End If
> Set gBaseClass = Nothing
> If Constants.DEBUG_MODE = True Then
> DEBUG_FILE.Write "AddinInstance_OnDisconnection: completed" &
> " " & Time & vbCrLf
> End If
> 'DebugWrite "AddinInstance_OnDisconnection"
> End Sub
>
> Private Sub AddinInstance_OnStartupComplete(custom() As Variant)
> '
> 'DebugWrite "AddinInstance OnStartupComplete"
> End Sub
>
>
>

Re: access to and subject of a wordmail item
"forums[ at ]webgremlins.net" <forums[ at ]webgremlins.net> 2/27/2007 4:34:37 PM
On 27 Feb, 15:29, "Ken Slovak - [MVP - Outlook]" <kenslo...[ at ]mvps.org>
wrote:
[Quoted Text]
> It looks like a relatively standard implementation of the ItemsCB VB6
> template.
>
> Don't do anything in NewInspector other than instantiating your Inspector
> class or event handler. Never call Inspector.Activate in that event. Wait
> for the first Inspector.Activate event to fire before adding your UI and
> doing anything else with that Inspector. In NewInspector you're given what's
> known as a "weak" object reference, where not all properties of the
> Inspector or Inspector.CurrentItem are populated. In NewInspector you really
> shouldn't be doing much else than checking for Inspector.CurrentItem.Class
> or Inspector.CurrentItem.MessageClass and then instantiating your Inspector
> handler or wrapper class.
>
> --
> Ken Slovak
> [MVP - Outlook]http://www.slovaktech.com
> Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
> Reminder Manager, Extended Reminders, Attachment Optionshttp://www.slovaktech.com/products.htm
>
> <for...[ at ]webgremlins.net> wrote in message
>
> news:1172585059.710141.158000[ at ]k78g2000cwa.googlegroups.com...
> <snip>
>
>
>
> > Hi Ken
>
> > Thankyou for the reply. I have gone trhough and stripped my code down.
> > I do hope it is a simple error!
>
> > I have this class calld OutAddIn
>
> > Option Explicit
> > 'Object variables for Event procedures
> > Private WithEvents objOutlook As Outlook.Application
> > Private WithEvents objWord As Word.Application
> > Private WithEvents objNS As Outlook.NameSpace
> > Private WithEvents objExpl As Outlook.Explorer
> > Private WithEvents colExpl As Outlook.Explorers
> > Private WithEvents objInsp As Outlook.Inspector
> > Private WithEvents colInsp As Outlook.Inspectors
> > Private WithEvents objMailItem As Outlook.MailItem
> > Private WithEvents objPostItem As Outlook.PostItem
> > Private WithEvents objContactItem As Outlook.ContactItem
> > Private WithEvents objDistListItem As Outlook.DistListItem
> > Private WithEvents objApptItem As Outlook.AppointmentItem
> > Private WithEvents objTaskItem As Outlook.TaskItem
> > Private WithEvents objJournalItem As Outlook.JournalItem
> > Private WithEvents objDocumentItem As Outlook.DocumentItem
>
> > '**************************************************************************­****
> > 'These event-aware objects are for Outlook 2002 only
> > 'Uncomment to use in Outlook 2002 COM Add-in
> > 'Private WithEvents colViews As Outlook.Views
> > 'Private WithEvents objResults As Outlook.Results
> > 'Private WithEvents colReminders As Outlook.Reminders
> > '**************************************************************************­****
> > 'Declare CommandBar, CommandBarButton, and CommandBarComboBox object
> > variables here
> > 'Don't use WithEvents for CommandBar object
> > 'Remove comments to declare object variables for CommandBar objects
> > 'Dim objCB As Office.CommandBar
> > 'Dim WithEvents objCBButton As Office.CommandBarButton
> > 'Dim WithEvents objCBComboBox As Office.CommandBarComboBox
> > oSendLogMenuBar
> > Dim objCBars As Office.CommandBars
> > Dim objCB As Office.CommandBar
> > Dim oMyControl As Office.CommandBarPopup
> > Dim bar As Office.CommandBar
>
> > Dim WithEvents oSealandSendMenuBar As Office.CommandBarButton
> > Dim WithEvents oVerifyMenuBar As Office.CommandBarButton
> > Dim WithEvents oVerifyExternalMenuBar As Office.CommandBarButton
> > Dim WithEvents oExtractMenuBar As Office.CommandBarButton
> > Dim WithEvents oAboutMenuBar As Office.CommandBarButton
> > Dim WithEvents oHelpMenuBar As Office.CommandBarButton
> > Dim WithEvents oSendLogMenuBar As Office.CommandBarButton
> > Dim WithEvents oWordSealandSendMenuBar As Office.CommandBarButton
>
> > Dim WithEvents oSealandSendToolBar As Office.CommandBarButton
> > Dim WithEvents oVerifyToolBar As Office.CommandBarButton
> > Dim WithEvents oExtractToolBar As Office.CommandBarButton
> > 'Dim WithEvents oTitleToolBar As Office.CommandBarButton
> > 'Dim WithEvents oValidateExternalToolBar As Office.CommandBarButton
>
> > 'controls for new inspector objects
> > Dim WithEvents oSealandSendNew As Office.CommandBarButton
> > Dim WithEvents oSealAttachmentNew As Office.CommandBarButton
> > Dim WithEvents oSealAllAttachmentsNew As Office.CommandBarButton
> > Dim WithEvents oVerifyNew As Office.CommandBarButton
> > Dim WithEvents oExtractNew As Office.CommandBarButton
>
> > Dim ShowSealAndSendControl As Boolean
> > Dim OutlookVersion As String
>
> > Private Declare Function ShellExecute Lib "shell32.dll" Alias
> > "ShellExecuteA" _
> > (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As
> > String, _
> > ByVal lpParameters As String, ByVal lpDirectory As String, ByVal
> > nShowCmd As Long) As Long
>
> > '**************************************************************************­****
>
> > '**************************************************************************­****
> > 'Custom procedure: InitHandler(olApp As Outlook.Application, strProgID
> > As String)
> > 'Purpose: Initialize event-aware object variables
> > '**************************************************************************­****
> > Friend Sub InitHandler(olApp As Outlook.Application, strProgID As
> > String)
>
> > 'On Error Resume Next
>
> > Set objOutlook = olApp 'Application Object
>
> > 'Instantiate a public module-level Outlook application variable
> > Set m_olApp = olApp
> > 'CDO Session if required
> > 'Uncomment for CDO
> > 'Set m_objCDO = CreateObject("MAPI.Session")
> > 'm_objCDO.Logon "", "", False, False
> > 'Declared WithEvents
> > Set objNS = objOutlook.GetNamespace("MAPI") 'NameSpace Object
> > 'Uncomment to use in Outlook 2002 COM Add-in
> > 'Set colReminders = objOutlook.Reminders 'Reminders Object
> > Set colExpl = objOutlook.Explorers 'Explorers Object
> > Set colInsp = objOutlook.Inspectors 'Inspectors Object
> > Set objExpl = objOutlook.ActiveExplorer 'Explorer Object
>
> > End Sub
>
> > 'detect the type, then bind the new inspector item to ObjMailitem
> > Private Sub colInsp_NewInspector(ByVal Inspector As Inspector)
>
> > Dim objItem As Outlook.MailItem
>
> > Set objInsp = Inspector
> > objInsp.Activate
> > Set objItem = objInsp.CurrentItem
> > Select Case objItem.Class
> > Case olMail
> > Set objMailItem = objItem
> > End Select
>
> > Set objItem = Nothing
> > End Sub
>
> > Private Sub objMailItem_Open(Cancel As Boolean)
> > Call addControls
> > End Sub
>
> > Private Sub addControls()
>
> > Dim cmdBar As Office.CommandBar
> > Dim cmdBars As Office.CommandBars
> > Set cmdBars = objMailItem.GetInspector.CommandBars
>
> > On Error Resume Next
> > Dim deletebar As Office.CommandBar
> > Set deletebar = cmdBars.Item("bar")
> > deletebar.Delete
> > deletebar = Nothing
> > On Error GoTo 0
>
> > Set cmdBar = cmdBars.Add("bar", 1, False, True)
>
> > Set oSealAllAttachmentsNew =
> > cmdBar.Controls.Add(Type:=msoControlButton, Temporary:=True)
> > oSealAllAttachmentsNew.Caption = "TruSeal &All Attachments"
> > oSealAllAttachmentsNew.ToolTipText = "Click here to Seal the
> > attachments on this email"
> > oSealAllAttachmentsNew.Tag = "oSealAllAttachmentsNew"
> > oSealAllAttachmentsNew.Style = msoButtonCaption
> > oSealAllAttachmentsNew.Visible = True
>
> > cmdBar.Visible = True
>
> > End Sub
>
> > 'when i detect here the to value, it doesnt show anything.
> > Private Sub oSealAllAttachmentsNew_click(ByVal Ctrl As
> > Office.CommandBarButton, CancelDefault As Boolean)
> > MsgBox objInsp.CurrentItem.To
> > End Sub
>
> > This is my designers connect class
>
> > Option Explicit
> > 'Use Implements IDTExtensibility2 in VB5 environment
> > 'Implements IDTExtensibility2
> > Private gBaseClass As New OutAddIn
>
> > Private Sub AddinInstance_OnAddInsUpdate(custom() As Variant)
> > 'DebugWrite "AddinInstance_OnAddInsUpdate"
> > End Sub
>
> > Private Sub AddinInstance_OnBeginShutdown(custom() As Variant)
> > 'DebugWrite "AddinInstance_OnBeginShutdown"
> > End Sub
>
> > Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
> > ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
> > ByVal AddInInst As Object, custom() As Variant)
>
> > 'On Error Resume Next
> > 'Evaluate ConnectMode
> > Select Case ConnectMode
> > Case ext_cm_Startup
> > Case ext_cm_AfterStartup
> > Case ext_cm_CommandLine
> > Case ext_cm_Startup
> > End Select
> > 'Don't call InitHandler if Explorers.Count = 0 and
> > Inspectors.Count = 0
> > If Application.Explorers.count = 0 And
> > Application.Inspectors.count = 0 Then
> > Exit Sub
> > End If
>
> > 'AddInInst represents COMAddIn object
> > 'Create and Initialize a base class
> > gBaseClass.InitHandler Application, AddInInst.ProgId
> > 'DebugWrite "IDT2 OnConnection"
>
> > End Sub
>
> > Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode _
> > As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
> > 'Tear down the class
> > 'IMPORTANT: This event will not fire when
> > 'RemoveMode = ext_dm_HostShutdown
> > 'It will fire when RemoveMode = ext_dm_UserClosed
>
> > 'gBaseClass.UnInitHandler
> > If RemoveMode = ext_dm_UserClosed Then
> > 'User shutdown removed COM Add-in
> > 'Cleanup custom toolbars by deleting them
> > Else
> > 'Host shutdown
> > End If
> > Set gBaseClass = Nothing
> > If Constants.DEBUG_MODE = True Then
> > DEBUG_FILE.Write "AddinInstance_OnDisconnection: completed" &
> > " " & Time & vbCrLf
> > End If
> > 'DebugWrite "AddinInstance_OnDisconnection"
> > End Sub
>
> > Private Sub AddinInstance_OnStartupComplete(custom() As Variant)
> > '
> > 'DebugWrite "AddinInstance OnStartupComplete"
> > End Sub- Hide quoted text -
>
> - Show quoted text -

Hi ken

Many thanks for the reply!

Ok, i have changed my newinspector code to the following


Private Sub colInsp_NewInspector(ByVal Inspector As Inspector)
Set objInsp = Inspector
End Sub


Then i have added ObjInsp_Activate

Public Sub objInsp_Activate()

Dim objItem As Outlook.MailItem
Set objItem = objInsp.CurrentItem
Select Case objItem.Class
Case olMail
Set objMailItem = objInsp.CurrentItem
Case olPost
'Set objPostItem = objItem
Case olAppointment
'Set objApptItem = objItem
Case olContact
'Set objContactItem = objItem
Case olDistributionList
'Set objDistListItem = objItem
Case olTask
'Set objTaskItem = objItem
Case olJournal
'Set objJournalItem = objItem
Case olDocument
'Set objDocumentItem = objItem
End Select
End Sub

So, i bind the ObjMailitem in the activate event, then the controls
are added in the Objmailitem_Open event, which is fired after the
activate event but i still cannot access the to and subject fields

Is this correct?

Many thanks

Jamie

Re: access to and subject of a wordmail item
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 2/27/2007 7:37:42 PM
As a test, in Inspector.Activate() try to retrieve objItem.Subject and
objItem.To.

As your code is written you will get an error if anything but a mail item is
being opened.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


<forums[ at ]webgremlins.net> wrote in message
news:1172594077.710107.271140[ at ]k78g2000cwa.googlegroups.com...

Hi ken

Many thanks for the reply!

Ok, i have changed my newinspector code to the following


Private Sub colInsp_NewInspector(ByVal Inspector As Inspector)
Set objInsp = Inspector
End Sub


Then i have added ObjInsp_Activate

Public Sub objInsp_Activate()

Dim objItem As Outlook.MailItem
Set objItem = objInsp.CurrentItem
Select Case objItem.Class
Case olMail
Set objMailItem = objInsp.CurrentItem
Case olPost
'Set objPostItem = objItem
Case olAppointment
'Set objApptItem = objItem
Case olContact
'Set objContactItem = objItem
Case olDistributionList
'Set objDistListItem = objItem
Case olTask
'Set objTaskItem = objItem
Case olJournal
'Set objJournalItem = objItem
Case olDocument
'Set objDocumentItem = objItem
End Select
End Sub

So, i bind the ObjMailitem in the activate event, then the controls
are added in the Objmailitem_Open event, which is fired after the
activate event but i still cannot access the to and subject fields

Is this correct?

Many thanks

Jamie

Re: access to and subject of a wordmail item
"forums[ at ]webgremlins.net" <forums[ at ]webgremlins.net> 3/1/2007 10:03:01 AM
Hi Ken

I have added the following to the activate event

msgbox objinsp.to

and

after binding

msgbox objmailitem.subject

and they both return empty strings with no errors

However, if i then enter an email address and a subject in wordmail
new mail form, then click my control and check objmailitem.to or
objmailitem.subject, they are an empty string. this is very strange.
It works fine if word is not the mail editor. i am testing using
outlook 2003

What is wierd, is that when i open a new word mail, the
objinsp_activate is fired several times, is this right?

is there some sort of event i can fire which sort of updates the
objinsp with the values entered in the new mail fields
programmatically?

cheers

Jamie




On 27 Feb, 19:37, "Ken Slovak - [MVP - Outlook]" <kenslo...[ at ]mvps.org>
wrote:
[Quoted Text]
> As a test, in Inspector.Activate() try to retrieve objItem.Subject and
> objItem.To.
>
> As your code is written you will get an error if anything but a mail item is
> being opened.
>
> --
> Ken Slovak
> [MVP - Outlook]http://www.slovaktech.com
> Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
> Reminder Manager, Extended Reminders, Attachment Optionshttp://www.slovaktech.com/products.htm
>
> <for...[ at ]webgremlins.net> wrote in message
>
> news:1172594077.710107.271140[ at ]k78g2000cwa.googlegroups.com...
>
> Hi ken
>
> Many thanks for the reply!
>
> Ok, i have changed my newinspector code to the following
>
> Private Sub colInsp_NewInspector(ByVal Inspector As Inspector)
> Set objInsp = Inspector
> End Sub
>
> Then i have added ObjInsp_Activate
>
> Public Sub objInsp_Activate()
>
> Dim objItem As Outlook.MailItem
> Set objItem = objInsp.CurrentItem
> Select Case objItem.Class
> Case olMail
> Set objMailItem = objInsp.CurrentItem
> Case olPost
> 'Set objPostItem = objItem
> Case olAppointment
> 'Set objApptItem = objItem
> Case olContact
> 'Set objContactItem = objItem
> Case olDistributionList
> 'Set objDistListItem = objItem
> Case olTask
> 'Set objTaskItem = objItem
> Case olJournal
> 'Set objJournalItem = objItem
> Case olDocument
> 'Set objDocumentItem = objItem
> End Select
> End Sub
>
> So, i bind the ObjMailitem in the activate event, then the controls
> are added in the Objmailitem_Open event, which is fired after the
> activate event but i still cannot access the to and subject fields
>
> Is this correct?
>
> Many thanks
>
> Jamie


Re: access to and subject of a wordmail item
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 3/1/2007 5:07:04 PM
More than 1 Activate event is normal. With WordMail you even get an extra
Activate event over the Outlook editor, as a sort of bonus <g>.

About all I can think of is that when you are entering subject and to and
are in the MailEnvelope portion of the WordMail window that the Outlook
Inspector hasn't yet been updated with that data. Unfortunately there's no
real way to read that mailenvelope data from the msoEnvelope wrapper.

You might be able to set the cursor to the body of the email by setting a
selection in the Document object (WordEditor). That might update the
Inspector.CurrentItem properties.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


<forums[ at ]webgremlins.net> wrote in message
news:1172743381.094984.247920[ at ]m58g2000cwm.googlegroups.com...
[Quoted Text]
> Hi Ken
>
> I have added the following to the activate event
>
> msgbox objinsp.to
>
> and
>
> after binding
>
> msgbox objmailitem.subject
>
> and they both return empty strings with no errors
>
> However, if i then enter an email address and a subject in wordmail
> new mail form, then click my control and check objmailitem.to or
> objmailitem.subject, they are an empty string. this is very strange.
> It works fine if word is not the mail editor. i am testing using
> outlook 2003
>
> What is wierd, is that when i open a new word mail, the
> objinsp_activate is fired several times, is this right?
>
> is there some sort of event i can fire which sort of updates the
> objinsp with the values entered in the new mail fields
> programmatically?
>
> cheers
>
> Jamie

Re: access to and subject of a wordmail item
"forums[ at ]webgremlins.net" <forums[ at ]webgremlins.net> 3/5/2007 12:16:08 PM
Hi Ken

I have found the solution!!

All you need to do is to do objmailitenm.save! and the fields are then
recognised!

It is always something really small!

Many thanks for your help on this one

Jamie :-)


On Mar 1, 5:07 pm, "Ken Slovak - [MVP - Outlook]" <kenslo...[ at ]mvps.org>
wrote:
[Quoted Text]
> More than 1 Activate event is normal. With WordMail you even get an extra
> Activate event over the Outlook editor, as a sort of bonus <g>.
>
> About all I can think of is that when you are entering subject and to and
> are in the MailEnvelope portion of the WordMail window that the Outlook
> Inspector hasn't yet been updated with that data. Unfortunately there's no
> real way to read that mailenvelope data from the msoEnvelope wrapper.
>
> You might be able to set the cursor to the body of the email by setting a
> selection in the Document object (WordEditor). That might update the
> Inspector.CurrentItem properties.
>
> --
> Ken Slovak
> [MVP - Outlook]http://www.slovaktech.com
> Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
> Reminder Manager, Extended Reminders, Attachment Optionshttp://www.slovaktech.com/products.htm
>
> <for...[ at ]webgremlins.net> wrote in message
>
> news:1172743381.094984.247920[ at ]m58g2000cwm.googlegroups.com...
>
>
>
> > Hi Ken
>
> > I have added the following to the activate event
>
> > msgbox objinsp.to
>
> > and
>
> > after binding
>
> > msgbox objmailitem.subject
>
> > and they both return empty strings with no errors
>
> > However, if i then enter an email address and a subject in wordmail
> > new mail form, then click my control and check objmailitem.to or
> > objmailitem.subject, they are an empty string. this is very strange.
> > It works fine if word is not the mail editor. i am testing using
> > outlook 2003
>
> > What is wierd, is that when i open a new word mail, the
> > objinsp_activate is fired several times, is this right?
>
> > is there some sort of event i can fire which sort of updates the
> > objinsp with the values entered in the new mail fields
> > programmatically?
>
> > cheers
>
> > Jamie- Hide quoted text -
>
> - Show quoted text -


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net