# What is an Outlook session?



## Dynamo Nath (Feb 24, 2010)

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


----------



## RoryA (Feb 24, 2010)

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.


----------



## Domski (Feb 24, 2010)

I'm only just starting to dabble with Outlook after many years on Lotus Notes but have found these resources which have all proved very useful.

http://www.outlookcode.com/Default.aspx

http://www.rondebruin.nl/sendmail.htm

http://www.codeforexcelandoutlook.com/

If you post the code you have we can see what is going on.

Dom


----------



## Dynamo Nath (Feb 24, 2010)

Here is the code I've been using:


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


----------



## RoryA (Feb 24, 2010)

You only need the Logon code if you have multiple accounts set up.


----------



## Dynamo Nath (Feb 24, 2010)

Ah ok, thanks for the explanation.


----------

