heb een code gevonden voor het automatisch laten verzenden van mail met outlook 2003.
nu loop ik tegen het probleem aan dat mijn tekst in de mail niet wordt weergegeven. als ik de orginele broncode erin zet geeft hij foutmelding op een aantal regels:
.Body = varBody< /FONT >
Set objOutlook = Nothing < /FONT >
als ik deze eruit gooi heb ik geen problemen meer, maar dat zal waarschijnlijk dan ook de reden zijn waarom ik geen tekst in de email krijg. Emailadres en onderwerp geven geen problemen.
bvd mic
hieronder de broncode:
________________________________________________________________
Sub SendMessage(strRecipient As String, strSubject As String, varBody As Variant, Optional strCC As String, Optional AttachmentPath)
On Error GoTo Err_subSendMessage
If Not (varBody > " ") Then
MsgBox "Geef de tekst op voor het e-mail bericht."
Exit Sub
End If
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
' Maak de Outlook-sessie.
Set objOutlook = CreateObject("Outlook.Application")
' Maak het bericht.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Voeg de geadresseerden voor het vak Aan toe aan het bericht.
Set objOutlookRecip = .Recipients.Add(strRecipient)
objOutlookRecip.Type = olTo
' Voeg de geadresseerden voor het vak CC toe aan het bericht.
If strCC > " " Then
Set objOutlookRecip = .Recipients.Add(strCC)
objOutlookRecip.Type = olCC
End If
' Stel het onderwerp, de berichttekst en de urgentie voor het bericht in.
.Subject = strSubject
.Body = varBody< /FONT >
'Stel eventueel in dat het bericht urgent is (hier uitgezet)
'.Importance = olImportanceHigh 'Hoge urgentie
' Voeg bijlagen toe aan het bericht.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Zet de naam van elke geadresseerde om.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
'Verstuur het e-mail bericht
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing < /FONT >
Exit_subSendMessage:
Exit Sub
Err_subSendMessage:
MsgBox Error
Resume Exit_subSendMessage
End Sub
nu loop ik tegen het probleem aan dat mijn tekst in de mail niet wordt weergegeven. als ik de orginele broncode erin zet geeft hij foutmelding op een aantal regels:
.Body = varBody< /FONT >
Set objOutlook = Nothing < /FONT >
als ik deze eruit gooi heb ik geen problemen meer, maar dat zal waarschijnlijk dan ook de reden zijn waarom ik geen tekst in de email krijg. Emailadres en onderwerp geven geen problemen.
bvd mic
hieronder de broncode:
________________________________________________________________
Sub SendMessage(strRecipient As String, strSubject As String, varBody As Variant, Optional strCC As String, Optional AttachmentPath)
On Error GoTo Err_subSendMessage
If Not (varBody > " ") Then
MsgBox "Geef de tekst op voor het e-mail bericht."
Exit Sub
End If
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
' Maak de Outlook-sessie.
Set objOutlook = CreateObject("Outlook.Application")
' Maak het bericht.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Voeg de geadresseerden voor het vak Aan toe aan het bericht.
Set objOutlookRecip = .Recipients.Add(strRecipient)
objOutlookRecip.Type = olTo
' Voeg de geadresseerden voor het vak CC toe aan het bericht.
If strCC > " " Then
Set objOutlookRecip = .Recipients.Add(strCC)
objOutlookRecip.Type = olCC
End If
' Stel het onderwerp, de berichttekst en de urgentie voor het bericht in.
.Subject = strSubject
.Body = varBody< /FONT >
'Stel eventueel in dat het bericht urgent is (hier uitgezet)
'.Importance = olImportanceHigh 'Hoge urgentie
' Voeg bijlagen toe aan het bericht.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Zet de naam van elke geadresseerde om.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
'Verstuur het e-mail bericht
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing < /FONT >
Exit_subSendMessage:
Exit Sub
Err_subSendMessage:
MsgBox Error
Resume Exit_subSendMessage
End Sub