I am trying to send mail from a specific account. This account in Outlook is not the default account. Really I have no idea what I am doing but am using this code that I found on http://stackoverflow.com/questions/...ow-to-choose-which-account-to-send-email-from. I need to build credits to ask a question there and therefore my post here. This code is also written for MS Access. I am using it in Excel.
On line
I get a compile error "Assignment to constant not permitted"
Here follows the code
__________________________________________________________________
On line
Code:
Set olAccount = oApp.Account
Here follows the code
Code:
Sub sendEventMail(em As String, ccc As String, Subj As String, desc As String)
On Error Resume Next
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(olMailItem)
Set olAccount = oApp.Account
Set olAccountTemp = oApp.Account
Dim foundAccount As Boolean
Dim strFrom As String
strFrom = "coastal@xtraordinarywomen.co.za"
foundAccount = False
Set olAccounts = oApp.Application.Session.Accounts
For Each olAccountTemp In olAccounts
Debug.Print olAccountTemp.smtpAddress
If (olAccountTemp.smtpAddress = strFrom) Then
Set olAccount = olAccountTemp
foundAccount = True
Exit For
End If
Next
If foundAccount Then
Debug.Print "ACCT FOUND!"
With oMail
.To = em
' .Body = "Message!"
.htmlBody = desc
.Subject = Subj
Set .SendUsingAccount = olAccount
End With
Else
Debug.Print "No acct found"
End If
Set oApp = Nothing
Set oMail = Nothing
Set olAccounts = Nothing
Set olAccount = Nothing
Set olAccountTemp = Nothing
End Sub
Mod edit : post moved to appropriate forum