What is an Outlook session?

Dynamo Nath

Board Regular
Joined
Aug 5, 2009
Messages
142
Hi,

I'm attempting to control Outlook from Excel and I have come across the session property. The starting point for my code used this property but if I remove it, the code still runs as before.

Can someone explain in simple terms what it means/does please? The help system reference doesn't really do that.

Thanks in advance, Nathan
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Session returns a reference to the Namespace which is an abstract object used to access a data source (in this case the MAPI data). The NameSpace is most often used (in my experience) for getting references to folders.
 
Upvote 0
Here is the code I've been using:

Code:
Public Sub create_email()
    Dim myoutlook As Outlook.Application
    Dim myemail As Outlook.MailItem
    Dim contact As Range
    Dim name As Variant
    Dim mysubject As Range
    Dim emailcount As Integer
    
    Set contact = Range(("a2"), Range("a2").End(xlDown))
    Set myoutlook = New Outlook.Application
    Set mysubject = Range("b2")
    
'    myoutlook.Session.Logon
    
    emailcount = 0
    
    For Each name In contact
    Set myemail = myoutlook.CreateItem(olMailItem)
        With myemail
            .To = name & "@"
            .Subject = mysubject.Offset(emailcount, 0).Value
        End With
        myemail.Display
    emailcount = emailcount + 1
    Next name
    
End Sub

The code I adapted this from used .session line commented out above. Out of curiosity as to what it did I commented it out and the code seems to work exactly as it did before. Hence me wondering what it did and whether or not it needed to be in there for some other purpose that I'm not using.
 
Upvote 0
You only need the Logon code if you have multiple accounts set up.
 
Upvote 0

Forum statistics

Threads
1,225,482
Messages
6,185,259
Members
453,283
Latest member
Shortm88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top