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
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
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

Am Sun, 11 Oct 2009 02:24:01 -0700 schrieb 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
 
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

"Michael Bauer " wrote:



> 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

> > >

> Am Sun, 11 Oct 2009 02:24:01 -0700 schrieb 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

>
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
You need to set the objExpl variable. As long as that's Nothing, you cannot

receive its events.

Best regards

Michael Bauer

Am Sun, 11 Oct 2009 19:31: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

> "Michael Bauer " wrote:
>
>

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

>> >> >>

>

>> Am Sun, 11 Oct 2009 02:24:01 -0700 schrieb 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

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

"Michael Bauer " wrote:



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

> > Best regards
> Michael Bauer

> > >

> Am Sun, 11 Oct 2009 19:31: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
> > "Michael Bauer " wrote:
> >
> >
> >
> >> 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
> >
> >> > >> > >>

> >
> >> Am Sun, 11 Oct 2009 02:24:01 -0700 schrieb 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
> >>

>
 

Similar threads

Top