Question on ThisOutlookSession or OutAddIn.cls methods.

  • Thread starter Thread starter paresh
  • Start date Start date
P

paresh

Hi,

I have noticed that below code works fine when I put it in
ThisOutlookSession or in OutAddIn.cls(Add-in's class module). Is it possible
to put this code in any module(modOutlook.bas) or designer(Connect.Dsr) and
make it works?

Thanks,
Paresh

My code in

Private WithEvents objExpl As Outlook.Explorer

Private Sub objExpl_SelectionChange()
Set objExpl = objOutlook.ActiveExplorer 'Explorer Object
If objExpl.Selection.Count > 0 Then
For Each objMailItem In objExpl.Selection
If objMailItem.Class = olMail Then
msgbox "email item";
End If
Next
End If
End Sub
 
It works in any class module, it doesn't in a standard module (*.bas). Just
try and copy the WithEvents declaration wherever you want to. If the
compiler complaints, it doesn't work.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>

Am Sun, 11 Oct 2009 02:24:01 -0700 schrieb paresh:
 
Thanks Michael but I kept below code in Connect.Dsr file in my VB Add-in and
it never invokes SelectionChange event. Am I doing something wrong?

Private WithEvents objExpl As Outlook.Explorer
Private myApp As Outlook.Application
Private Sub objExpl_SelectionChange()
MsgBox "came here"
Dim objMailItem As Object
Set objExpl = myApp.ActiveExplorer 'Explorer Object
If objExpl.Selection.Count > 0 Then
For Each objMailItem In objExpl.Selection
If objMailItem.Class = olMail Then
MsgBox "email item"
End If
Next
End If
End Sub

Thanks,
Paresh
 
You need to set the objExpl variable. As long as that's Nothing, you cannot
receive its events.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Sun, 11 Oct 2009 19:31:01 -0700 schrieb paresh:
 
Okay got it. I will need to put below line in start up routine then.

Set objExpl = myApp.ActiveExplorer 'Explorer Object

Thanks,
Paresh
 
Back
Top