Attachment-objekt falsche Syntax?
05.02.2021 16:12:01
Ronald
Ich möchte gerne E-Mails mit Anhang versenden. Leider geht es nicht. Die Route sieht so aus:
Dim applOutlook As Outlook.Application
Dim nsOutlook As Outlook.Namespace
Dim objMail As Object
Dim oAccount As Account
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments
Dim strAbsender As String
Dim strEMailAdresse As String
strAbsender = "service@tuboly-astronic.ch"
Set applOutlook = New Outlook.Application
Set nsOutlook = applOutlook.GetNamespace("MAPI")
Set objMail = applOutlook.CreateItem(0)
'Gehört zu Variante 1:
Set myItem = Application.CreateItem(olMailItem)
Set myAttachments = myItem.Attachments
myAttachments.Add "C:\_Transfer zu Remote Desktop\User+Pass Tu-As-machines.pdf"
'strEMailVorschauAttachm = "C:\_Transfer zu Remote Desktop\User+Pass Tu-As-machines.pdf" _
If chkVorschau.Value = True Then
'E-Mail schicken mit Vorschau
frmVorschau.Show
If boolEmailOK = True Then
'Routine fürs E-Mail schicken
For Each oAccount In applOutlook.Session.Accounts
If oAccount = strEMailAdresse Then 'oAccount.DisplayName
With objMail
.To = "Ronald@test.de"
.Subject = strServiceID
.Body = "Mein Text"
.Attachments.Add = myAttachments '
Ich habe verschiedene Möglichkeiten probiert, einen Anhang von der Festplatte anzuhängen, aber
bisher wurden diese immer auf irgendeine Art und Weise nicht unterstützt. Also stelle ich mir die
Frage, wie denn die richtige Vorgehensweise wäre.
Ich habe auch bei Microsoft direkt geguckt, also hier:
https://docs.microsoft.com/de-de/office/vba/api/outlook.attachment
Aber auch das hab nicht funktioniert. Daher bitte ich um Eure Hilfe.
Danke im Voraus.
Gruß Ronald