A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Tags: , , , ,

Problems accesing created bookmark in VBA





 
 
Thread Tools Display Modes
  #1  
Old January 11th 07, 01:49 PM posted to microsoft.public.outlook.program_vba
epsilon_9
external usenet poster
 
Posts: 7
Default Problems accesing created bookmark in VBA

Hi

I am trying t create a macro for outlook where e-mail signatures are
inserted depending on if recipients names are resolved or not i.e if there is
an "@" in any of the recipients fields

I have created a class module with a MailItem object and it handles certain
events. I created a bookmark (_MailAutoSig) that the word editor of outlook
apparently uses to insert signatures. I have been able to create the bookmark
when a mail is opned but in another MailItem eventhandler
(item_BeforeCheckNames) I am unable to access the bookmark. I keep gettin an
error indicating that the bookmark does not exist even after using the edit
got menu command of word editor to access the bookmark.

Extracts from my code are below. Any help will be appreciated

The following is the class module (clsInspector)

Option Explicit


Dim WithEvents oAppInspectors As Outlook.Inspectors
Dim WithEvents oOpenMail As Outlook.MailItem
Dim oAppInspector As Outlook.Inspector
Dim oDoc As Word.Document
Dim oSel As Word.Selection

Dim oCB As Office.CommandBar
Dim colCBControls As Office.CommandBarControls
Dim oCBB As Office.CommandBarButton
'Class Initialize
Private Sub Class_Initialize()
'oAppInspectors Returns a handle to the Inspectors collection
Set oAppInspectors = Application.Inspectors
End Sub



Private Sub oAppInspectors_NewInspector(ByVal Inspector As Inspector)
'Event gets triggered every time a Window or Item is opened in Outlook
Interface
'Like: E-mail, Contacts, Tasks

If Inspector.CurrentItem.Class olMail Then
'Only deal with Email Items...else exit
Exit Sub
End If
'Set a reference to the e-mail inspector
Set oAppInspector = Inspector
'Set a reference to the e-mail to trap the Open event
Set oOpenMail = Inspector.CurrentItem
End Sub

Private Sub oOpenMail_BeforeCheckNames(Cancel As Boolean)
'Dim oRcpnt As Outlook.Recipient
'Dim oRcpnts As Outlook.Recipients

If oAppInspector.EditorType = olEditorWord Then

Set oDoc = oAppInspector.WordEditor
Set oSel = oDoc.Application.Selection

If InStr(oOpenMail.To, "@") Or InStr(oOpenMail.CC, "@") Or
InStr(oOpenMail.BCC, "@") Then

'oSel.GoTo What:=wdGoToBookmark, Name:="\StartOfDoc"

oDoc.Bookmarks.ShowHidden = True
Debug.Print oDoc.Bookmarks.Count

oSel.GoTo What:=wdGoToBookmark, Name:="_MailAutoSig"
'oDoc.Bookmarks("_MailAutoSig").Select


Set oCB = oDoc.CommandBars("AutoSignature Popup")
If Not oCB Is Nothing Then
Set colCBControls = oCB.Controls
End If

If Not colCBControls Is Nothing Then
For Each oCBB In colCBControls
If oCBB.Caption = "AD Signature" Then
oCBB.Execute
Exit For
End If
Next
End If
End If

End If
End Sub
Private Sub oOpenMail_Open(Cancel As Boolean)

'Event gets triggered if oOpenMail is opened!
If oAppInspector.EditorType = olEditorWord Then
' next statement will trigger security prompt
' in Outlook 2002 SP3
Set oDoc = oAppInspector.WordEditor
Set oSel = oDoc.Application.Selection
If Not oDoc.Bookmarks.Exists("_MailAutoSig") Then
oSel.TypeParagraph
oSel.TypeParagraph
oDoc.Bookmarks.Add Range:=oSel.Range, Name:="_MailAutoSig"
End If
Debug.Print oDoc.Bookmarks.Count

'oSel.GoTo What:=wdGoToBookmark, Name:="_MailAutoSig"
'Set oCB = oDoc.CommandBars("AutoSignature Popup")
'If Not oCB Is Nothing Then
'Set colCBControls = oCB.Controls
'End If

'If Not colCBControls Is Nothing Then
'For Each oCBB In colCBControls
'If oCBB.Caption = "AD Signature" Then
'oCBB.Execute
'Exit For
'End If
'Next
'End If

oSel.GoTo What:=wdGoToBookmark, Name:="\StartOfDoc"

End If
End Sub

The following is the declaration and initialisation of the class module in
the ThisoutlookSession module

Dim TrapInspector As clsInspector



Private Sub Application_Startup()
On Error Resume Next

'Event gets triggered when you start Outlook
'Initialize class "clsInspector"
Set TrapInspector = New clsInspector

Thanks
Andy.
Ads
  #2  
Old January 12th 07, 08:30 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,264
Default Problems accesing created bookmark in VBA



If you can access the bookmark in the first event, what happens if you store
that reference and use it in the BeforeCheckNames event?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Thu, 11 Jan 2007 04:49:00 -0800 schrieb epsilon_9:

Hi

I am trying t create a macro for outlook where e-mail signatures are
inserted depending on if recipients names are resolved or not i.e if there

is
an "@" in any of the recipients fields

I have created a class module with a MailItem object and it handles

certain
events. I created a bookmark (_MailAutoSig) that the word editor of

outlook
apparently uses to insert signatures. I have been able to create the

bookmark
when a mail is opned but in another MailItem eventhandler
(item_BeforeCheckNames) I am unable to access the bookmark. I keep gettin

an
error indicating that the bookmark does not exist even after using the

edit
got menu command of word editor to access the bookmark.

Extracts from my code are below. Any help will be appreciated

The following is the class module (clsInspector)

Option Explicit


Dim WithEvents oAppInspectors As Outlook.Inspectors
Dim WithEvents oOpenMail As Outlook.MailItem
Dim oAppInspector As Outlook.Inspector
Dim oDoc As Word.Document
Dim oSel As Word.Selection

Dim oCB As Office.CommandBar
Dim colCBControls As Office.CommandBarControls
Dim oCBB As Office.CommandBarButton
'Class Initialize
Private Sub Class_Initialize()
'oAppInspectors Returns a handle to the Inspectors collection
Set oAppInspectors = Application.Inspectors
End Sub



Private Sub oAppInspectors_NewInspector(ByVal Inspector As Inspector)
'Event gets triggered every time a Window or Item is opened in

Outlook
Interface
'Like: E-mail, Contacts, Tasks

If Inspector.CurrentItem.Class olMail Then
'Only deal with Email Items...else exit
Exit Sub
End If
'Set a reference to the e-mail inspector
Set oAppInspector = Inspector
'Set a reference to the e-mail to trap the Open event
Set oOpenMail = Inspector.CurrentItem
End Sub

Private Sub oOpenMail_BeforeCheckNames(Cancel As Boolean)
'Dim oRcpnt As Outlook.Recipient
'Dim oRcpnts As Outlook.Recipients

If oAppInspector.EditorType = olEditorWord Then

Set oDoc = oAppInspector.WordEditor
Set oSel = oDoc.Application.Selection

If InStr(oOpenMail.To, "@") Or InStr(oOpenMail.CC, "@") Or
InStr(oOpenMail.BCC, "@") Then

'oSel.GoTo What:=wdGoToBookmark, Name:="\StartOfDoc"

oDoc.Bookmarks.ShowHidden = True
Debug.Print oDoc.Bookmarks.Count

oSel.GoTo What:=wdGoToBookmark, Name:="_MailAutoSig"
'oDoc.Bookmarks("_MailAutoSig").Select


Set oCB = oDoc.CommandBars("AutoSignature Popup")
If Not oCB Is Nothing Then
Set colCBControls = oCB.Controls
End If

If Not colCBControls Is Nothing Then
For Each oCBB In colCBControls
If oCBB.Caption = "AD Signature" Then
oCBB.Execute
Exit For
End If
Next
End If
End If

End If
End Sub
Private Sub oOpenMail_Open(Cancel As Boolean)

'Event gets triggered if oOpenMail is opened!
If oAppInspector.EditorType = olEditorWord Then
' next statement will trigger security prompt
' in Outlook 2002 SP3
Set oDoc = oAppInspector.WordEditor
Set oSel = oDoc.Application.Selection
If Not oDoc.Bookmarks.Exists("_MailAutoSig") Then
oSel.TypeParagraph
oSel.TypeParagraph
oDoc.Bookmarks.Add Range:=oSel.Range, Name:="_MailAutoSig"
End If
Debug.Print oDoc.Bookmarks.Count

'oSel.GoTo What:=wdGoToBookmark, Name:="_MailAutoSig"
'Set oCB = oDoc.CommandBars("AutoSignature Popup")
'If Not oCB Is Nothing Then
'Set colCBControls = oCB.Controls
'End If

'If Not colCBControls Is Nothing Then
'For Each oCBB In colCBControls
'If oCBB.Caption = "AD Signature" Then
'oCBB.Execute
'Exit For
'End If
'Next
'End If

oSel.GoTo What:=wdGoToBookmark, Name:="\StartOfDoc"

End If
End Sub

The following is the declaration and initialisation of the class module in
the ThisoutlookSession module

Dim TrapInspector As clsInspector



Private Sub Application_Startup()
On Error Resume Next

'Event gets triggered when you start Outlook
'Initialize class "clsInspector"
Set TrapInspector = New clsInspector

Thanks
Andy.

  #3  
Old January 12th 07, 11:07 AM posted to microsoft.public.outlook.program_vba
epsilon_9
external usenet poster
 
Posts: 7
Default Problems accesing created bookmark in VBA

It gives me a runtime error saying "Object has been deleted". On further
investigation i relaised that the signature gets deleted before the
BeforeCheckNames event fires. I guess I have to look for an event that gets
fired before the send button is clicked but after the recepient fields (To CC
BCC) have been changed. I don't know if thats possible using wordmail as the
mail editor

Andy.

"Michael Bauer [MVP - Outlook]" wrote:



If you can access the bookmark in the first event, what happens if you store
that reference and use it in the BeforeCheckNames event?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Thu, 11 Jan 2007 04:49:00 -0800 schrieb epsilon_9:

Hi

I am trying t create a macro for outlook where e-mail signatures are
inserted depending on if recipients names are resolved or not i.e if there

is
an "@" in any of the recipients fields

I have created a class module with a MailItem object and it handles

certain
events. I created a bookmark (_MailAutoSig) that the word editor of

outlook
apparently uses to insert signatures. I have been able to create the

bookmark
when a mail is opned but in another MailItem eventhandler
(item_BeforeCheckNames) I am unable to access the bookmark. I keep gettin

an
error indicating that the bookmark does not exist even after using the

edit
got menu command of word editor to access the bookmark.

Extracts from my code are below. Any help will be appreciated

The following is the class module (clsInspector)

Option Explicit


Dim WithEvents oAppInspectors As Outlook.Inspectors
Dim WithEvents oOpenMail As Outlook.MailItem
Dim oAppInspector As Outlook.Inspector
Dim oDoc As Word.Document
Dim oSel As Word.Selection

Dim oCB As Office.CommandBar
Dim colCBControls As Office.CommandBarControls
Dim oCBB As Office.CommandBarButton
'Class Initialize
Private Sub Class_Initialize()
'oAppInspectors Returns a handle to the Inspectors collection
Set oAppInspectors = Application.Inspectors
End Sub



Private Sub oAppInspectors_NewInspector(ByVal Inspector As Inspector)
'Event gets triggered every time a Window or Item is opened in

Outlook
Interface
'Like: E-mail, Contacts, Tasks

If Inspector.CurrentItem.Class olMail Then
'Only deal with Email Items...else exit
Exit Sub
End If
'Set a reference to the e-mail inspector
Set oAppInspector = Inspector
'Set a reference to the e-mail to trap the Open event
Set oOpenMail = Inspector.CurrentItem
End Sub

Private Sub oOpenMail_BeforeCheckNames(Cancel As Boolean)
'Dim oRcpnt As Outlook.Recipient
'Dim oRcpnts As Outlook.Recipients

If oAppInspector.EditorType = olEditorWord Then

Set oDoc = oAppInspector.WordEditor
Set oSel = oDoc.Application.Selection

If InStr(oOpenMail.To, "@") Or InStr(oOpenMail.CC, "@") Or
InStr(oOpenMail.BCC, "@") Then

'oSel.GoTo What:=wdGoToBookmark, Name:="\StartOfDoc"

oDoc.Bookmarks.ShowHidden = True
Debug.Print oDoc.Bookmarks.Count

oSel.GoTo What:=wdGoToBookmark, Name:="_MailAutoSig"
'oDoc.Bookmarks("_MailAutoSig").Select


Set oCB = oDoc.CommandBars("AutoSignature Popup")
If Not oCB Is Nothing Then
Set colCBControls = oCB.Controls
End If

If Not colCBControls Is Nothing Then
For Each oCBB In colCBControls
If oCBB.Caption = "AD Signature" Then
oCBB.Execute
Exit For
End If
Next
End If
End If

End If
End Sub
Private Sub oOpenMail_Open(Cancel As Boolean)

'Event gets triggered if oOpenMail is opened!
If oAppInspector.EditorType = olEditorWord Then
' next statement will trigger security prompt
' in Outlook 2002 SP3
Set oDoc = oAppInspector.WordEditor
Set oSel = oDoc.Application.Selection
If Not oDoc.Bookmarks.Exists("_MailAutoSig") Then
oSel.TypeParagraph
oSel.TypeParagraph
oDoc.Bookmarks.Add Range:=oSel.Range, Name:="_MailAutoSig"
End If
Debug.Print oDoc.Bookmarks.Count

'oSel.GoTo What:=wdGoToBookmark, Name:="_MailAutoSig"
'Set oCB = oDoc.CommandBars("AutoSignature Popup")
'If Not oCB Is Nothing Then
'Set colCBControls = oCB.Controls
'End If

'If Not colCBControls Is Nothing Then
'For Each oCBB In colCBControls
'If oCBB.Caption = "AD Signature" Then
'oCBB.Execute
'Exit For
'End If
'Next
'End If

oSel.GoTo What:=wdGoToBookmark, Name:="\StartOfDoc"

End If
End Sub

The following is the declaration and initialisation of the class module in
the ThisoutlookSession module

Dim TrapInspector As clsInspector



Private Sub Application_Startup()
On Error Resume Next

'Event gets triggered when you start Outlook
'Initialize class "clsInspector"
Set TrapInspector = New clsInspector

Thanks
Andy.


  #4  
Old January 15th 07, 07:28 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,264
Default Problems accesing created bookmark in VBA



You could add the bookmark in the oOpenMail_BeforeCheckNames event, couldn't
you?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Fri, 12 Jan 2007 02:07:01 -0800 schrieb epsilon_9:

It gives me a runtime error saying "Object has been deleted". On further
investigation i relaised that the signature gets deleted before the
BeforeCheckNames event fires. I guess I have to look for an event that

gets
fired before the send button is clicked but after the recepient fields (To

CC
BCC) have been changed. I don't know if thats possible using wordmail as

the
mail editor

Andy.

"Michael Bauer [MVP - Outlook]" wrote:



If you can access the bookmark in the first event, what happens if you

store
that reference and use it in the BeforeCheckNames event?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Thu, 11 Jan 2007 04:49:00 -0800 schrieb epsilon_9:

Hi

I am trying t create a macro for outlook where e-mail signatures are
inserted depending on if recipients names are resolved or not i.e if

there
is
an "@" in any of the recipients fields

I have created a class module with a MailItem object and it handles

certain
events. I created a bookmark (_MailAutoSig) that the word editor of

outlook
apparently uses to insert signatures. I have been able to create the

bookmark
when a mail is opned but in another MailItem eventhandler
(item_BeforeCheckNames) I am unable to access the bookmark. I keep

gettin
an
error indicating that the bookmark does not exist even after using the

edit
got menu command of word editor to access the bookmark.

Extracts from my code are below. Any help will be appreciated

The following is the class module (clsInspector)

Option Explicit


Dim WithEvents oAppInspectors As Outlook.Inspectors
Dim WithEvents oOpenMail As Outlook.MailItem
Dim oAppInspector As Outlook.Inspector
Dim oDoc As Word.Document
Dim oSel As Word.Selection

Dim oCB As Office.CommandBar
Dim colCBControls As Office.CommandBarControls
Dim oCBB As Office.CommandBarButton
'Class Initialize
Private Sub Class_Initialize()
'oAppInspectors Returns a handle to the Inspectors collection
Set oAppInspectors = Application.Inspectors
End Sub



Private Sub oAppInspectors_NewInspector(ByVal Inspector As Inspector)
'Event gets triggered every time a Window or Item is opened in

Outlook
Interface
'Like: E-mail, Contacts, Tasks

If Inspector.CurrentItem.Class olMail Then
'Only deal with Email Items...else exit
Exit Sub
End If
'Set a reference to the e-mail inspector
Set oAppInspector = Inspector
'Set a reference to the e-mail to trap the Open event
Set oOpenMail = Inspector.CurrentItem
End Sub

Private Sub oOpenMail_BeforeCheckNames(Cancel As Boolean)
'Dim oRcpnt As Outlook.Recipient
'Dim oRcpnts As Outlook.Recipients

If oAppInspector.EditorType = olEditorWord Then

Set oDoc = oAppInspector.WordEditor
Set oSel = oDoc.Application.Selection

If InStr(oOpenMail.To, "@") Or InStr(oOpenMail.CC, "@") Or
InStr(oOpenMail.BCC, "@") Then

'oSel.GoTo What:=wdGoToBookmark, Name:="\StartOfDoc"

oDoc.Bookmarks.ShowHidden = True
Debug.Print oDoc.Bookmarks.Count

oSel.GoTo What:=wdGoToBookmark, Name:="_MailAutoSig"
'oDoc.Bookmarks("_MailAutoSig").Select


Set oCB = oDoc.CommandBars("AutoSignature Popup")
If Not oCB Is Nothing Then
Set colCBControls = oCB.Controls
End If

If Not colCBControls Is Nothing Then
For Each oCBB In colCBControls
If oCBB.Caption = "AD Signature" Then
oCBB.Execute
Exit For
End If
Next
End If
End If

End If
End Sub
Private Sub oOpenMail_Open(Cancel As Boolean)

'Event gets triggered if oOpenMail is opened!
If oAppInspector.EditorType = olEditorWord Then
' next statement will trigger security prompt
' in Outlook 2002 SP3
Set oDoc = oAppInspector.WordEditor
Set oSel = oDoc.Application.Selection
If Not oDoc.Bookmarks.Exists("_MailAutoSig") Then
oSel.TypeParagraph
oSel.TypeParagraph
oDoc.Bookmarks.Add Range:=oSel.Range, Name:="_MailAutoSig"
End If
Debug.Print oDoc.Bookmarks.Count

'oSel.GoTo What:=wdGoToBookmark, Name:="_MailAutoSig"
'Set oCB = oDoc.CommandBars("AutoSignature Popup")
'If Not oCB Is Nothing Then
'Set colCBControls = oCB.Controls
'End If

'If Not colCBControls Is Nothing Then
'For Each oCBB In colCBControls
'If oCBB.Caption = "AD Signature" Then
'oCBB.Execute
'Exit For
'End If
'Next
'End If

oSel.GoTo What:=wdGoToBookmark, Name:="\StartOfDoc"

End If
End Sub

The following is the declaration and initialisation of the class module

in
the ThisoutlookSession module

Dim TrapInspector As clsInspector



Private Sub Application_Startup()
On Error Resume Next

'Event gets triggered when you start Outlook
'Initialize class "clsInspector"
Set TrapInspector = New clsInspector

Thanks
Andy.


  #5  
Old January 15th 07, 12:55 PM posted to microsoft.public.outlook.program_vba
epsilon_9
external usenet poster
 
Posts: 7
Default Problems accesing created bookmark in VBA

Yes come to think of it now I actually could, simple and effective. Because
of positioning reasons the bookmark has to be created when a new mailitem is
opened for editing. I could actually create a normal bookmark (non hidden as
these seem not to be deleted by outlook when the oOpenMail_BeforeCheckNames
event gets called) then change it to the required bookmark (_MailAutoSig) and
utilise it for my purposes then. Thanks Micheal will try it out

Andy.

"Michael Bauer [MVP - Outlook]" wrote:



You could add the bookmark in the oOpenMail_BeforeCheckNames event, couldn't
you?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Fri, 12 Jan 2007 02:07:01 -0800 schrieb epsilon_9:

It gives me a runtime error saying "Object has been deleted". On further
investigation i relaised that the signature gets deleted before the
BeforeCheckNames event fires. I guess I have to look for an event that

gets
fired before the send button is clicked but after the recepient fields (To

CC
BCC) have been changed. I don't know if thats possible using wordmail as

the
mail editor

Andy.

"Michael Bauer [MVP - Outlook]" wrote:



If you can access the bookmark in the first event, what happens if you

store
that reference and use it in the BeforeCheckNames event?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Thu, 11 Jan 2007 04:49:00 -0800 schrieb epsilon_9:

Hi

I am trying t create a macro for outlook where e-mail signatures are
inserted depending on if recipients names are resolved or not i.e if

there
is
an "@" in any of the recipients fields

I have created a class module with a MailItem object and it handles
certain
events. I created a bookmark (_MailAutoSig) that the word editor of
outlook
apparently uses to insert signatures. I have been able to create the
bookmark
when a mail is opned but in another MailItem eventhandler
(item_BeforeCheckNames) I am unable to access the bookmark. I keep

gettin
an
error indicating that the bookmark does not exist even after using the
edit
got menu command of word editor to access the bookmark.

Extracts from my code are below. Any help will be appreciated

The following is the class module (clsInspector)

Option Explicit


Dim WithEvents oAppInspectors As Outlook.Inspectors
Dim WithEvents oOpenMail As Outlook.MailItem
Dim oAppInspector As Outlook.Inspector
Dim oDoc As Word.Document
Dim oSel As Word.Selection

Dim oCB As Office.CommandBar
Dim colCBControls As Office.CommandBarControls
Dim oCBB As Office.CommandBarButton
'Class Initialize
Private Sub Class_Initialize()
'oAppInspectors Returns a handle to the Inspectors collection
Set oAppInspectors = Application.Inspectors
End Sub



Private Sub oAppInspectors_NewInspector(ByVal Inspector As Inspector)
'Event gets triggered every time a Window or Item is opened in
Outlook
Interface
'Like: E-mail, Contacts, Tasks

If Inspector.CurrentItem.Class olMail Then
'Only deal with Email Items...else exit
Exit Sub
End If
'Set a reference to the e-mail inspector
Set oAppInspector = Inspector
'Set a reference to the e-mail to trap the Open event
Set oOpenMail = Inspector.CurrentItem
End Sub

Private Sub oOpenMail_BeforeCheckNames(Cancel As Boolean)
'Dim oRcpnt As Outlook.Recipient
'Dim oRcpnts As Outlook.Recipients

If oAppInspector.EditorType = olEditorWord Then

Set oDoc = oAppInspector.WordEditor
Set oSel = oDoc.Application.Selection

If InStr(oOpenMail.To, "@") Or InStr(oOpenMail.CC, "@") Or
InStr(oOpenMail.BCC, "@") Then

'oSel.GoTo What:=wdGoToBookmark, Name:="\StartOfDoc"

oDoc.Bookmarks.ShowHidden = True
Debug.Print oDoc.Bookmarks.Count

oSel.GoTo What:=wdGoToBookmark, Name:="_MailAutoSig"
'oDoc.Bookmarks("_MailAutoSig").Select


Set oCB = oDoc.CommandBars("AutoSignature Popup")
If Not oCB Is Nothing Then
Set colCBControls = oCB.Controls
End If

If Not colCBControls Is Nothing Then
For Each oCBB In colCBControls
If oCBB.Caption = "AD Signature" Then
oCBB.Execute
Exit For
End If
Next
End If
End If

End If
End Sub
Private Sub oOpenMail_Open(Cancel As Boolean)

'Event gets triggered if oOpenMail is opened!
If oAppInspector.EditorType = olEditorWord Then
' next statement will trigger security prompt
' in Outlook 2002 SP3
Set oDoc = oAppInspector.WordEditor
Set oSel = oDoc.Application.Selection
If Not oDoc.Bookmarks.Exists("_MailAutoSig") Then
oSel.TypeParagraph
oSel.TypeParagraph
oDoc.Bookmarks.Add Range:=oSel.Range, Name:="_MailAutoSig"
End If
Debug.Print oDoc.Bookmarks.Count

'oSel.GoTo What:=wdGoToBookmark, Name:="_MailAutoSig"
'Set oCB = oDoc.CommandBars("AutoSignature Popup")
'If Not oCB Is Nothing Then
'Set colCBControls = oCB.Controls
'End If

'If Not colCBControls Is Nothing Then
'For Each oCBB In colCBControls
'If oCBB.Caption = "AD Signature" Then
'oCBB.Execute
'Exit For
'End If
'Next
'End If

oSel.GoTo What:=wdGoToBookmark, Name:="\StartOfDoc"

End If
End Sub

The following is the declaration and initialisation of the class module

in
the ThisoutlookSession module

Dim TrapInspector As clsInspector



Private Sub Application_Startup()
On Error Resume Next

'Event gets triggered when you start Outlook
'Initialize class "clsInspector"
Set TrapInspector = New clsInspector

Thanks
Andy.


  #6  
Old January 15th 07, 06:17 PM posted to microsoft.public.outlook.program_vba
epsilon_9
external usenet poster
 
Posts: 7
Default Problems accesing created bookmark in VBA

Hi Micheal

Tried it out and it worked but warning message comes up askin if i want to
save changes made and when i click yes it says "The item has been moved or
deleted". So clearly I can't edit the content of the mail after the send
button has been clicked.
below is the event handler as it is

Private Sub oOpenMail_BeforeCheckNames(Cancel As Boolean)
'Dim oRcpnt As Outlook.Recipient
'Dim oRcpnts As Outlook.Recipients

If oAppInspector.EditorType = olEditorWord Then

'Set oDoc = oAppInspector.WordEditor
'Set oSel = oDoc.Application.Selection

If InStr(oOpenMail.To, "@") Or InStr(oOpenMail.CC, "@") Or
InStr(oOpenMail.BCC, "@") Then

Debug.Print oDoc.Bookmarks.Count

oSel.GoTo What:=wdGoToBookmark, Name:="MailAutoSig"

oDoc.Bookmarks("MailAutoSig").Delete

oDoc.Bookmarks.Add Range:=oSel.Range, Name:="_MailAutoSig"

Set oCB = oDoc.CommandBars("AutoSignature Popup")
If Not oCB Is Nothing Then
Set colCBControls = oCB.Controls
End If

If Not colCBControls Is Nothing Then
For Each oCBB In colCBControls
If oCBB.Caption = "AD Signature" Then
oCBB.Execute
Exit For
End If
Next
End If



End If

End If
End Sub

Any help will be greatlt appreciated

Thanks.



"epsilon_9" wrote:

Yes come to think of it now I actually could, simple and effective. Because
of positioning reasons the bookmark has to be created when a new mailitem is
opened for editing. I could actually create a normal bookmark (non hidden as
these seem not to be deleted by outlook when the oOpenMail_BeforeCheckNames
event gets called) then change it to the required bookmark (_MailAutoSig) and
utilise it for my purposes then. Thanks Micheal will try it out

Andy.

"Michael Bauer [MVP - Outlook]" wrote:



You could add the bookmark in the oOpenMail_BeforeCheckNames event, couldn't
you?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Fri, 12 Jan 2007 02:07:01 -0800 schrieb epsilon_9:

It gives me a runtime error saying "Object has been deleted". On further
investigation i relaised that the signature gets deleted before the
BeforeCheckNames event fires. I guess I have to look for an event that

gets
fired before the send button is clicked but after the recepient fields (To

CC
BCC) have been changed. I don't know if thats possible using wordmail as

the
mail editor

Andy.

"Michael Bauer [MVP - Outlook]" wrote:



If you can access the bookmark in the first event, what happens if you

store
that reference and use it in the BeforeCheckNames event?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Thu, 11 Jan 2007 04:49:00 -0800 schrieb epsilon_9:

Hi

I am trying t create a macro for outlook where e-mail signatures are
inserted depending on if recipients names are resolved or not i.e if

there
is
an "@" in any of the recipients fields

I have created a class module with a MailItem object and it handles
certain
events. I created a bookmark (_MailAutoSig) that the word editor of
outlook
apparently uses to insert signatures. I have been able to create the
bookmark
when a mail is opned but in another MailItem eventhandler
(item_BeforeCheckNames) I am unable to access the bookmark. I keep

gettin
an
error indicating that the bookmark does not exist even after using the
edit
got menu command of word editor to access the bookmark.

Extracts from my code are below. Any help will be appreciated

The following is the class module (clsInspector)

Option Explicit


Dim WithEvents oAppInspectors As Outlook.Inspectors
Dim WithEvents oOpenMail As Outlook.MailItem
Dim oAppInspector As Outlook.Inspector
Dim oDoc As Word.Document
Dim oSel As Word.Selection

Dim oCB As Office.CommandBar
Dim colCBControls As Office.CommandBarControls
Dim oCBB As Office.CommandBarButton
'Class Initialize
Private Sub Class_Initialize()
'oAppInspectors Returns a handle to the Inspectors collection
Set oAppInspectors = Application.Inspectors
End Sub



Private Sub oAppInspectors_NewInspector(ByVal Inspector As Inspector)
'Event gets triggered every time a Window or Item is opened in
Outlook
Interface
'Like: E-mail, Contacts, Tasks

If Inspector.CurrentItem.Class olMail Then
'Only deal with Email Items...else exit
Exit Sub
End If
'Set a reference to the e-mail inspector
Set oAppInspector = Inspector
'Set a reference to the e-mail to trap the Open event
Set oOpenMail = Inspector.CurrentItem
End Sub

Private Sub oOpenMail_BeforeCheckNames(Cancel As Boolean)
'Dim oRcpnt As Outlook.Recipient
'Dim oRcpnts As Outlook.Recipients

If oAppInspector.EditorType = olEditorWord Then

Set oDoc = oAppInspector.WordEditor
Set oSel = oDoc.Application.Selection

If InStr(oOpenMail.To, "@") Or InStr(oOpenMail.CC, "@") Or
InStr(oOpenMail.BCC, "@") Then

'oSel.GoTo What:=wdGoToBookmark, Name:="\StartOfDoc"

oDoc.Bookmarks.ShowHidden = True
Debug.Print oDoc.Bookmarks.Count

oSel.GoTo What:=wdGoToBookmark, Name:="_MailAutoSig"
'oDoc.Bookmarks("_MailAutoSig").Select


Set oCB = oDoc.CommandBars("AutoSignature Popup")
If Not oCB Is Nothing Then
Set colCBControls = oCB.Controls
End If

If Not colCBControls Is Nothing Then
For Each oCBB In colCBControls
If oCBB.Caption = "AD Signature" Then
oCBB.Execute
Exit For
End If
Next
End If
End If

End If
End Sub
Private Sub oOpenMail_Open(Cancel As Boolean)

'Event gets triggered if oOpenMail is opened!
If oAppInspector.EditorType = olEditorWord Then
' next statement will trigger security prompt
' in Outlook 2002 SP3
Set oDoc = oAppInspector.WordEditor
Set oSel = oDoc.Application.Selection
If Not oDoc.Bookmarks.Exists("_MailAutoSig") Then
oSel.TypeParagraph
oSel.TypeParagraph
oDoc.Bookmarks.Add Range:=oSel.Range, Name:="_MailAutoSig"
End If
Debug.Print oDoc.Bookmarks.Count

'oSel.GoTo What:=wdGoToBookmark, Name:="_MailAutoSig"
'Set oCB = oDoc.CommandBars("AutoSignature Popup")
'If Not oCB Is Nothing Then
'Set colCBControls = oCB.Controls
'End If

'If Not colCBControls Is Nothing Then
'For Each oCBB In colCBControls
'If oCBB.Caption = "AD Signature" Then
'oCBB.Execute
'Exit For
'End If
'Next
'End If

oSel.GoTo What:=wdGoToBookmark, Name:="\StartOfDoc"

End If
End Sub

The following is the declaration and initialisation of the class module

in
the ThisoutlookSession module

Dim TrapInspector As clsInspector



Private Sub Application_Startup()
On Error Resume Next

'Event gets triggered when you start Outlook
'Initialize class "clsInspector"
Set TrapInspector = New clsInspector

Thanks
Andy.


  #7  
Old January 17th 07, 06:47 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,264
Default Problems accesing created bookmark in VBA



If you want to run the code after Send button was clicked then use the
ItemSend event instead of BeforeCheckNames. I don't have problems to edit
the content in that event.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Mon, 15 Jan 2007 09:17:01 -0800 schrieb epsilon_9:

Hi Micheal

Tried it out and it worked but warning message comes up askin if i want to
save changes made and when i click yes it says "The item has been moved or
deleted". So clearly I can't edit the content of the mail after the send
button has been clicked.
below is the event handler as it is

Private Sub oOpenMail_BeforeCheckNames(Cancel As Boolean)
'Dim oRcpnt As Outlook.Recipient
'Dim oRcpnts As Outlook.Recipients

If oAppInspector.EditorType = olEditorWord Then

'Set oDoc = oAppInspector.WordEditor
'Set oSel = oDoc.Application.Selection

If InStr(oOpenMail.To, "@") Or InStr(oOpenMail.CC, "@") Or
InStr(oOpenMail.BCC, "@") Then

Debug.Print oDoc.Bookmarks.Count

oSel.GoTo What:=wdGoToBookmark, Name:="MailAutoSig"

oDoc.Bookmarks("MailAutoSig").Delete

oDoc.Bookmarks.Add Range:=oSel.Range, Name:="_MailAutoSig"

Set oCB = oDoc.CommandBars("AutoSignature Popup")
If Not oCB Is Nothing Then
Set colCBControls = oCB.Controls
End If

If Not colCBControls Is Nothing Then
For Each oCBB In colCBControls
If oCBB.Caption = "AD Signature" Then
oCBB.Execute
Exit For
End If
Next
End If



End If

End If
End Sub

Any help will be greatlt appreciated

Thanks.



"epsilon_9" wrote:

Yes come to think of it now I actually could, simple and effective.

Because
of positioning reasons the bookmark has to be created when a new mailitem

is
opened for editing. I could actually create a normal bookmark (non hidden

as
these seem not to be deleted by outlook when the

oOpenMail_BeforeCheckNames
event gets called) then change it to the required bookmark (_MailAutoSig)

and
utilise it for my purposes then. Thanks Micheal will try it out

Andy.

"Michael Bauer [MVP - Outlook]" wrote:



You could add the bookmark in the oOpenMail_BeforeCheckNames event,

couldn't
you?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Fri, 12 Jan 2007 02:07:01 -0800 schrieb epsilon_9:

It gives me a runtime error saying "Object has been deleted". On

further
investigation i relaised that the signature gets deleted before the
BeforeCheckNames event fires. I guess I have to look for an event that
gets
fired before the send button is clicked but after the recepient fields

(To
CC
BCC) have been changed. I don't know if thats possible using wordmail

as
the
mail editor

Andy.

"Michael Bauer [MVP - Outlook]" wrote:



If you can access the bookmark in the first event, what happens if

you
store
that reference and use it in the BeforeCheckNames event?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!

http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Thu, 11 Jan 2007 04:49:00 -0800 schrieb epsilon_9:

Hi

I am trying t create a macro for outlook where e-mail signatures are
inserted depending on if recipients names are resolved or not i.e if
there
is
an "@" in any of the recipients fields

I have created a class module with a MailItem object and it handles
certain
events. I created a bookmark (_MailAutoSig) that the word editor of
outlook
apparently uses to insert signatures. I have been able to create the
bookmark
when a mail is opned but in another MailItem eventhandler
(item_BeforeCheckNames) I am unable to access the bookmark. I keep
gettin
an
error indicating that the bookmark does not exist even after using

the
edit
got menu command of word editor to access the bookmark.

Extracts from my code are below. Any help will be appreciated

The following is the class module (clsInspector)

Option Explicit


Dim WithEvents oAppInspectors As Outlook.Inspectors
Dim WithEvents oOpenMail As Outlook.MailItem
Dim oAppInspector As Outlook.Inspector
Dim oDoc As Word.Document
Dim oSel As Word.Selection

Dim oCB As Office.CommandBar
Dim colCBControls As Office.CommandBarControls
Dim oCBB As Office.CommandBarButton
'Class Initialize
Private Sub Class_Initialize()
'oAppInspectors Returns a handle to the Inspectors collection
Set oAppInspectors = Application.Inspectors
End Sub



Private Sub oAppInspectors_NewInspector(ByVal Inspector As

Inspector)
'Event gets triggered every time a Window or Item is opened in
Outlook
Interface
'Like: E-mail, Contacts, Tasks

If Inspector.CurrentItem.Class olMail Then
'Only deal with Email Items...else exit
Exit Sub
End If
'Set a reference to the e-mail inspector
Set oAppInspector = Inspector
'Set a reference to the e-mail to trap the Open event
Set oOpenMail = Inspector.CurrentItem
End Sub

Private Sub oOpenMail_BeforeCheckNames(Cancel As Boolean)
'Dim oRcpnt As Outlook.Recipient
'Dim oRcpnts As Outlook.Recipients

If oAppInspector.EditorType = olEditorWord Then

Set oDoc = oAppInspector.WordEditor
Set oSel = oDoc.Application.Selection

If InStr(oOpenMail.To, "@") Or InStr(oOpenMail.CC, "@")

Or
InStr(oOpenMail.BCC, "@") Then

'oSel.GoTo What:=wdGoToBookmark, Name:="\StartOfDoc"

oDoc.Bookmarks.ShowHidden = True
Debug.Print oDoc.Bookmarks.Count

oSel.GoTo What:=wdGoToBookmark, Name:="_MailAutoSig"
'oDoc.Bookmarks("_MailAutoSig").Select


Set oCB = oDoc.CommandBars("AutoSignature Popup")
If Not oCB Is Nothing Then
Set colCBControls = oCB.Controls
End If

If Not colCBControls Is Nothing Then
For Each oCBB In colCBControls
If oCBB.Caption = "AD Signature" Then
oCBB.Execute
Exit For
End If
Next
End If
End If

End If
End Sub
Private Sub oOpenMail_Open(Cancel As Boolean)

'Event gets triggered if oOpenMail is opened!
If oAppInspector.EditorType = olEditorWord Then
' next statement will trigger security prompt
' in Outlook 2002 SP3
Set oDoc = oAppInspector.WordEditor
Set oSel = oDoc.Application.Selection
If Not oDoc.Bookmarks.Exists("_MailAutoSig") Then
oSel.TypeParagraph
oSel.TypeParagraph
oDoc.Bookmarks.Add Range:=oSel.Range,

Name:="_MailAutoSig"
End If
Debug.Print oDoc.Bookmarks.Count

'oSel.GoTo What:=wdGoToBookmark, Name:="_MailAutoSig"
'Set oCB = oDoc.CommandBars("AutoSignature Popup")
'If Not oCB Is Nothing Then
'Set colCBControls = oCB.Controls
'End If

'If Not colCBControls Is Nothing Then
'For Each oCBB In colCBControls
'If oCBB.Caption = "AD Signature" Then
'oCBB.Execute
'Exit For
'End If
'Next
'End If

oSel.GoTo What:=wdGoToBookmark, Name:="\StartOfDoc"

End If
End Sub

The following is the declaration and initialisation of the class

module
in
the ThisoutlookSession module

Dim TrapInspector As clsInspector



Private Sub Application_Startup()
On Error Resume Next

'Event gets triggered when you start Outlook
'Initialize class "clsInspector"
Set TrapInspector = New clsInspector

Thanks
Andy.


  #8  
Old January 17th 07, 12:17 PM posted to microsoft.public.outlook.program_vba
epsilon_9
external usenet poster
 
Posts: 7
Default Problems accesing created bookmark in VBA

Tried it, doesn't work if you are using word as your mail editor and trying
to access the body of the mail throught the document object gotten from the
WordEditor object of the activeinspector (i.e currently open mail item). It
does work if you are accesing the body of the mail through the HTMLBody
property of the mail item but that defeats the pupose of creating a bookmark
and using all the other wordmail functionality that i did earlier. I think
I'll have to find an object that responds to changes in the TO, BCC or CC
fields while the fileds are being edited (was told the wordmail envelope
doesn't expose any events, tested that notion and found it to be true at
least for objects of the microsoft outlook library), I'm guessing I can find
one in the windows 32 object library. Ofcourse I'll welcome any suggestions
you have

Thank you
Andy

"Michael Bauer [MVP - Outlook]" wrote:



If you want to run the code after Send button was clicked then use the
ItemSend event instead of BeforeCheckNames. I don't have problems to edit
the content in that event.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Mon, 15 Jan 2007 09:17:01 -0800 schrieb epsilon_9:

Hi Micheal

Tried it out and it worked but warning message comes up askin if i want to
save changes made and when i click yes it says "The item has been moved or
deleted". So clearly I can't edit the content of the mail after the send
button has been clicked.
below is the event handler as it is

Private Sub oOpenMail_BeforeCheckNames(Cancel As Boolean)
'Dim oRcpnt As Outlook.Recipient
'Dim oRcpnts As Outlook.Recipients

If oAppInspector.EditorType = olEditorWord Then

'Set oDoc = oAppInspector.WordEditor
'Set oSel = oDoc.Application.Selection

If InStr(oOpenMail.To, "@") Or InStr(oOpenMail.CC, "@") Or
InStr(oOpenMail.BCC, "@") Then

Debug.Print oDoc.Bookmarks.Count

oSel.GoTo What:=wdGoToBookmark, Name:="MailAutoSig"

oDoc.Bookmarks("MailAutoSig").Delete

oDoc.Bookmarks.Add Range:=oSel.Range, Name:="_MailAutoSig"

Set oCB = oDoc.CommandBars("AutoSignature Popup")
If Not oCB Is Nothing Then
Set colCBControls = oCB.Controls
End If

If Not colCBControls Is Nothing Then
For Each oCBB In colCBControls
If oCBB.Caption = "AD Signature" Then
oCBB.Execute
Exit For
End If
Next
End If



End If

End If
End Sub

Any help will be greatlt appreciated

Thanks.



"epsilon_9" wrote:

Yes come to think of it now I actually could, simple and effective.

Because
of positioning reasons the bookmark has to be created when a new mailitem

is
opened for editing. I could actually create a normal bookmark (non hidden

as
these seem not to be deleted by outlook when the

oOpenMail_BeforeCheckNames
event gets called) then change it to the required bookmark (_MailAutoSig)

and
utilise it for my purposes then. Thanks Micheal will try it out

Andy.

"Michael Bauer [MVP - Outlook]" wrote:



You could add the bookmark in the oOpenMail_BeforeCheckNames event,

couldn't
you?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Fri, 12 Jan 2007 02:07:01 -0800 schrieb epsilon_9:

It gives me a runtime error saying "Object has been deleted". On

further
investigation i relaised that the signature gets deleted before the
BeforeCheckNames event fires. I guess I have to look for an event that
gets
fired before the send button is clicked but after the recepient fields

(To
CC
BCC) have been changed. I don't know if thats possible using wordmail

as
the
mail editor

Andy.

"Michael Bauer [MVP - Outlook]" wrote:



If you can access the bookmark in the first event, what happens if

you
store
that reference and use it in the BeforeCheckNames event?

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!

http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Thu, 11 Jan 2007 04:49:00 -0800 schrieb epsilon_9:

Hi

I am trying t create a macro for outlook where e-mail signatures are
inserted depending on if recipients names are resolved or not i.e if
there
is
an "@" in any of the recipients fields

I have created a class module with a MailItem object and it handles
certain
events. I created a bookmark (_MailAutoSig) that the word editor of
outlook
apparently uses to insert signatures. I have been able to create the
bookmark
when a mail is opned but in another MailItem eventhandler
(item_BeforeCheckNames) I am unable to access the bookmark. I keep
gettin
an
error indicating that the bookmark does not exist even after using

the
edit
got menu command of word editor to access the bookmark.

Extracts from my code are below. Any help will be appreciated

The following is the class module (clsInspector)

Option Explicit


Dim WithEvents oAppInspectors As Outlook.Inspectors
Dim WithEvents oOpenMail As Outlook.MailItem
Dim oAppInspector As Outlook.Inspector
Dim oDoc As Word.Document
Dim oSel As Word.Selection

Dim oCB As Office.CommandBar
Dim colCBControls As Office.CommandBarControls
Dim oCBB As Office.CommandBarButton
'Class Initialize
Private Sub Class_Initialize()
'oAppInspectors Returns a handle to the Inspectors collection
Set oAppInspectors = Application.Inspectors
End Sub



Private Sub oAppInspectors_NewInspector(ByVal Inspector As

Inspector)
'Event gets triggered every time a Window or Item is opened in
Outlook
Interface
'Like: E-mail, Contacts, Tasks

If Inspector.CurrentItem.Class olMail Then
'Only deal with Email Items...else exit
Exit Sub
End If
'Set a reference to the e-mail inspector
Set oAppInspector = Inspector
'Set a reference to the e-mail to trap the Open event
Set oOpenMail = Inspector.CurrentItem
End Sub

Private Sub oOpenMail_BeforeCheckNames(Cancel As Boolean)
'Dim oRcpnt As Outlook.Recipient
'Dim oRcpnts As Outlook.Recipients

If oAppInspector.EditorType = olEditorWord Then

Set oDoc = oAppInspector.WordEditor
Set oSel = oDoc.Application.Selection

If InStr(oOpenMail.To, "@") Or InStr(oOpenMail.CC, "@")

Or
InStr(oOpenMail.BCC, "@") Then

'oSel.GoTo What:=wdGoToBookmark, Name:="\StartOfDoc"

oDoc.Bookmarks.ShowHidden = True
Debug.Print oDoc.Bookmarks.Count

oSel.GoTo What:=wdGoToBookmark, Name:="_MailAutoSig"
'oDoc.Bookmarks("_MailAutoSig").Select


Set oCB = oDoc.CommandBars("AutoSignature Popup")
If Not oCB Is Nothing Then
Set colCBControls = oCB.Controls
End If

If Not colCBControls Is Nothing Then
For Each oCBB In colCBControls
If oCBB.Caption = "AD Signature" Then
oCBB.Execute
Exit For
End If
Next
End If
End If

End If
End Sub
Private Sub oOpenMail_Open(Cancel As Boolean)

'Event gets triggered if oOpenMail is opened!
If oAppInspector.EditorType = olEditorWord Then
' next statement will trigger security prompt
' in Outlook 2002 SP3
Set oDoc = oAppInspector.WordEditor
Set oSel = oDoc.Application.Selection
If Not oDoc.Bookmarks.Exists("_MailAutoSig") Then
oSel.TypeParagraph
oSel.TypeParagraph
oDoc.Bookmarks.Add Range:=oSel.Range,

Name:="_MailAutoSig"
End If
Debug.Print oDoc.Bookmarks.Count

'oSel.GoTo What:=wdGoToBookmark, Name:="_MailAutoSig"
'Set oCB = oDoc.CommandBars("AutoSignature Popup")
'If Not oCB Is Nothing Then
'Set colCBControls = oCB.Controls
'End If

'If Not colCBControls Is Nothing Then
'For Each oCBB In colCBControls
'If oCBB.Caption = "AD Signature" Then
'oCBB.Execute
'Exit For
'End If
'Next
'End If

oSel.GoTo What:=wdGoToBookmark, Name:="\StartOfDoc"

End If
End Sub

The following is the declaration and initialisation of the class

module
in
the ThisoutlookSession module

Dim TrapInspector As clsInspector



Private Sub Application_Startup()
On Error Resume Next

'Event gets triggered when you start Outlook
'Initialize class "clsInspector"
Set TrapInspector = New clsInspector

Thanks
Andy.



  #9  
Old January 18th 07, 07:04 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,264
Default Problems accesing created bookmark in VBA


PropertyChange responds to changes in To, CC and BCC.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Wed, 17 Jan 2007 03:17:00 -0800 schrieb epsilon_9:

Tried it, doesn't work if you are using word as your mail editor and

trying
to access the body of the mail throught the document object gotten from

the
WordEditor object of the activeinspector (i.e currently open mail item).

It
does work if you are accesing the body of the mail through the HTMLBody
property of the mail item but that defeats the pupose of creating a

bookmark
and using all the other wordmail functionality that i did earlier. I think
I'll have to find an object that responds to changes in the TO, BCC or CC
fields while the fileds are being edited (was told the wordmail envelope
doesn't expose any events, tested that notion and found it to be true at
least for objects of the microsoft outlook library), I'm guessing I can

find
one in the windows 32 object library. Ofcourse I'll welcome any

suggestions
you have

Thank you
Andy

"Michael Bauer [MVP - Outlook]" wrote:



If you want to run the code after Send button was clicked then use the
ItemSend event instead of BeforeCheckNames. I don't have problems to edit
the content in that event.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Mon, 15 Jan 2007 09:17:01 -0800 schrieb epsilon_9:

Hi Micheal

Tried it out and it worked but warning message comes up askin if i want

to
save changes made and when i click yes it says "The item has been moved

or
deleted". So clearly I can't edit the content of the mail after the send
button has been clicked.
below is the event handler as it is

Private Sub oOpenMail_BeforeCheckNames(Cancel As Boolean)
'Dim oRcpnt As Outlook.Recipient