I made the changes you suggested and am still having problems. I even recopied all of the code. The only part that I changed so far, was to change the e-mail address from
user@website.com to my e-mail address, and I enclosed that in quotation marks. I added Microsoft Outlook 12.0 Object Library as a reference (I didn't have the option of 14.0). When I inserted the breaking point and then tried to run through it, I still received the same message listed below and a message stating that an "object is required". This message appeared on the line showing Set mailOutlook = appOutlook.CreateItem(olMailItem). Incidentally, I don't need attachments on this e-mail, just the message - if that makes a difference. Is there something I can do to get the Outlook 14.0 object library. Would that make a difference? What do you suggest? Below is the code that I have right now.
Sub Outlook_SendMail()
Outlook_OpenOutlook 'this is a sub further down the page
Dim mailOutlook As Outlook.MailItem
Dim strDoc As String
'strDoc = CurrentProject.Path & "\sample.docx"
'if you wish to add an attachment
Set mailOutlook = appOutlook.CreateItem(olMailItem)
With mailOutlook
.Subject = "Sample email" 'place subject here
.To = "
diane@rr.com"
.Body = "Sample Body." ' place text here
'.Attachments.Add strDoc 'attach the doc
' display the email
.Display
'send the email
.send
End With
Set mailOutlook = Nothing
End Sub
Sub Outlook_OpenOutlook()
' Initialize outlook objects
On Error Resume Next
Set appOutlook = GetObject(, "Outlook.Application")
If Err <> 0 Then
' attempt to start outlook
' Note that this code can be used to start a second instance of outlook
Set appOutlook = New Outlook.Application
Set namespaceOutlook = appOutlook.GetNamespace("MAPI")
Dim folderOutlook As Folder
Set folderOutlook = namespaceOutlook.GetDefaultFolder(olFolderInbox)
' make outlook visible on the desktop
folderOutlook.Display
Else
Set namespaceOutlook = appOutlook.GetNamespace("MAPI")
End If
End Sub
Private Sub Command212_Click()
Outlook_SendMail
End Sub