View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Steven Kelder Steven Kelder is offline
external usenet poster
 
Posts: 2
Default Creating a MailItem in Outlook from Excel using Late Binding

Hi there, thanks for your Attention !! Excel 2002, WinXP

I have problems with the Following Code, copied from the excellent site
http://www.dicks-clicks.com, with some changes introduced by me.

I want to use Late Binding.

The problem is with the line:

Set olMail = olApp.CreateItem(olMailItem),

which gives Compile Error "Variable not Defined".

The previous line:
Set olNs = olApp.GetNamespace("MAPI")
I left in the code without really undestanding what I need it for...

Following is the Code, and Really thanks for your time !!!
Steven Kelder

Sub SendResults()
Dim olApp As Object
Dim olNs As Object
Dim olMail As Object 'Late Binding-generic Object data type

'Activate Outlook if it isn't Open yet:
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")

If Err.Number = 429 Then
Set olApp = CreateObject("Outlook.application")
End If

On Error GoTo 0
'End Activate Outlook

Set olNs = olApp.GetNamespace("MAPI") 'Do I need this ??
Set olMail = olApp.CreateItem(olMailItem)

'Send Mail:
With olMail
.To = "
.Subject = "Sample Subject"
.Body = "Sample Body Text" & vbCrLf
.Send
End With

Set olNs = Nothing
Set olApp = Nothing
End Sub