Question on ThisOutlookSession or OutAddIn.cls methods.

Status
Not open for further replies.
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

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

>
 
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

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

>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
P Question on ThisOutlookSession or OutAddIn.cls methods. Outlook VBA and Custom Forms 1
G Question marks in messages Using Outlook 2
e_a_g_l_e_p_i Question about calendar Using Outlook 5
e_a_g_l_e_p_i Question about installing my Gmail account on my iPhone but still getting messages downloaded to my desktop Outlook. Using Outlook 3
e_a_g_l_e_p_i Question about reinstalling Outlook 2021 Using Outlook 5
e_a_g_l_e_p_i question about 2-Step Verification with my gmail Using Outlook 0
D Question on removing an alias Using Outlook 1
O Newbie question: how to sync two Outlook -Exchange and IMAP- calendars? Using Outlook 4
D a general question re how backup programs handle pst files ... I have no problems, just curious Using Outlook 1
e_a_g_l_e_p_i A few question before I decide to switch to Pop from imap Using Outlook 9
D.Moore SendAndReceive question Outlook VBA and Custom Forms 2
J Transport Rule to detect Keyword question.. Exchange Server Administration 2
N Question Using Outlook 8
D Shared Mailbox question Exchange Server Administration 1
CWM030 Another Quarantine question Exchange Server Administration 0
E Outlook 2010 Can somebody tell me , the question associated with OST format Using Outlook 1
CWM030 A quick question for Diane about Exchange Exchange Server Administration 2
CWM030 Email Catagorties question Using Outlook 1
MahdeeyaAbdulla Friend's outlook question Using Outlook 1
e_a_g_l_e_p_i Question about address book in Outlook 2010 Using Outlook 9
M Question about nested distribution lists Outlook VBA and Custom Forms 3
e_a_g_l_e_p_i A question about installing office 2013 Pro and using my .pst from office 2010 Using Outlook 12
rerun101 Question about message options Outlook VBA and Custom Forms 4
M Question: Is there a rule that will save email in Windows Explorer Outlook VBA and Custom Forms 3
M Question on address book Using Outlook 1
e_a_g_l_e_p_i question about saving my .pst so I can import it to my Outlook after I build a new system Using Outlook 10
V Question on pop email Using Outlook 2
D a general question regarding data files Using Outlook 3
R Outlook 2007 - Email Question - POP3 to IMAP Outlook VBA and Custom Forms 11
D Advanced Search Question Using Outlook 1
adaminaus Quick question if i may Using Outlook 4
T Business Projects question BCM (Business Contact Manager) 0
V question about personal and shared calendars Exchange Server Administration 1
A Basic BCM question about sync to Outlook 2013 BCM (Business Contact Manager) 1
Jeff Rott Diane Question on "Use in a Run a Script Rule" Outlook VBA and Custom Forms 1
C Custom Forms: Question about retaining form information throughout the entire conversation Outlook VBA and Custom Forms 2
D OST question Exchange Server Administration 5
Mr Mayor Another recurring meeting question Using Outlook 1
V iCloud question Using Outlook 3
J "Specific word in body" question Using Outlook 1
A Newb-ish question Using Outlook 2
A The hardest VBA/Outlook question yet Using Outlook 1
S DAG question Exchange Server Administration 0
P Outlook File Extension Question Using Outlook 3
J Outlook 2010 Calendaring Question Using Outlook 0
K Syncing outlook with iCloud question Using Outlook 5
T Outlook Prf/Automation question Using Outlook 2
T Settings question Using Outlook 6
D Question re: Grouping by Due Date vs. Sorting by Due Date Using Outlook 1
IGWright Outlook 2013 .pst Question Using Outlook 10

Similar threads

Back
Top