walty.ch
Goto Top

Fehler beim Kompilieren End Sub erwartet

Sub DocAlsAnhangSenden()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then
MsgBox "Dokument muss erst gespeichert werden"
Exit Sub
End If
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.To = "test@example.com" '<-- E-Mail-Adresse
.Subject = "Word Dokument als Anhang versenden"
.Attachments.Add Source:=ActiveDocument.FullName, _
Type:=olByValue, _
DisplayName:="Dokument als Attachment"
.Send
End With
If bStarted Then
oOutlookApp.Quit
End If
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub

Dies ist der Text von PCtipp.ch, mit der Antwort: Funktioniert einwandfrei!
Bei mir kommt obige Fehlermeldung, die ich mit End Sub anstelle von Exit Sub (probiere) korrigiere.
Dann kommt die Fehlermeldung: Code kann im Haltemodus nicht ausgeführt werden. > Neustart von Word (2013) > Es kommt wieder der Fehler:
Fehler beim Kompilieren End Sub erwartet.
Setze ein End Sub in die zweite Zeile.

Kein Fehler mehr, keine Reaktion!

Wie versende ich mit einem Makro ein Word (2013) Dokument als Email (oder Email Anhang) !??!

Content-Key: 216442

Url: https://administrator.de/contentid/216442

Ausgedruckt am: 28.03.2024 um 09:03 Uhr

Mitglied: 106543
106543 09.09.2013 um 14:02:18 Uhr
Goto Top
Kein Fehler mehr, keine Reaktion!

Kann dir sagen, warum du keine Fehlermeldung bekommst.
Wenn du "On Error Resume Next" drin hast ist das die Holzhammermethode. Sobald ein Fehler auftritt, wird dieser Ignoriert und es wird weitergearbeitet. Lass das weg und schau was für eine Fehlermeldung du bekommst.

Grüße
Exze
Mitglied: walty.ch
walty.ch 12.09.2013 um 12:06:21 Uhr
Goto Top
Es funktioniert jetzt! Es sieht so aus

Sub DocAlsAnhangSenden()
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
If Len(ActiveDocument.Path) = 0 Then
MsgBox "Dokument muss erst gespeichert werden"
Exit Sub
End If
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.To = "tester@versuch.ch" '<-- E-Mail-Adresse
.Subject = "Word Test Dokument als Anhang versenden"
.Attachments.Add Source:=ActiveDocument.FullName, _
Type:=olByValue, _
DisplayName:="Dokument als Attachment"
.Body = "Besten Dank für Ihren Auftrag." & Chr(13) & _
"Mit freundlichen Grüssen" & Chr(13) _

.Send
End With
If bStarted Then
oOutlookApp.Quit
End If
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub


Was ich nicht geschafft habe ist eine dritte Zeile nach Mit freundlichen Grüssen. Keine Ahnung warum.

Bin aber auch erst wieder am "Neu Anfang", nach zehn Jahren Unterbruch. Da hat sich einiges geändert.

Nehme mal erwähnte Zeile noch raus. mal schauen was geht!??!

Erst mal Danke.