Question on ThisOutlookSession or OutAddIn.cls methods.

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
 
M

Michael Bauer [MVP - Outlook]

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:
 
P

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
 
M

Michael Bauer [MVP - Outlook]

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:
 
P

paresh

Okay got it. I will need to put below line in start up routine then.

Set objExpl = myApp.ActiveExplorer 'Explorer Object

Thanks,
Paresh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top