walty.ch
Goto Top

Word Dokument als Email senden

Habe ein Makro erstellt um das Dokument als Anhang zu senden. Nun sollte dies aber als PDF gesendet werden.


Sub EmailSenden()

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
ActiveDocument.SendMail
.Subject = "Word Test Dokument als Anhang versenden, WGM"
.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


Bin auf Hilfe angewiesen, da ich keine Ahnung von Makro seit Office2003 habe. Wir Benutzen Office 2007 und Ofice2013.
Dieses Makro habe ich mit verschiedenen Forenbeiträgen zusammen gezimmert! Und es funktioniert, aber als Word Datei.


Danke!

Content-Key: 217047

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

Printed on: April 23, 2024 at 06:04 o'clock

Member: colinardo
colinardo Sep 16, 2013 updated at 13:36:27 (UTC)
Goto Top
Hallo walty.ch,
ab Word 2007 kannst du die integrierte Funktion zum Speichern als PDF verwenden und dann dieses Dokument an eine Outlook-Mail anhängen:
Beispiel:
Sub SendMailasPDF()
    If ActiveDocument.Path = "" Then  
        MsgBox "Dokument muss erst gespeichert werden!", vbExclamation  
        Exit Sub
    End If
    Set objOL = CreateObject("Outlook.Application")  
    strTempPath = Environ("TEMP")  
    strFileNameNoExtension = Mid(ActiveDocument.Name, 1, InStrRev(ActiveDocument.Name, ".", -1, vbTextCompare) - 1)  
    strPDFPath = strTempPath & "\" & strFileNameNoExtension & ".pdf"  
    ActiveDocument.SaveAs2 FileName:=strPDFPath, FileFormat:=wdFormatPDF
    Set objMail = objOL.CreateItem(0)
    With objMail
        .Subject = "Dein Betreff"  
        .Body = "Mit freundlichen Grüßen"  
        .Attachments.Add strPDFPath
        .Display
    End With
    Set objOL = Nothing
End Sub
Grüße Uwe
Member: walty.ch
walty.ch Sep 16, 2013 updated at 14:10:39 (UTC)
Goto Top
SUPER!!!

Vielen Dank, Deine Version ist nicht mal halb so gross wie meine (nicht funktionierende)!


Danke
Member: colinardo
colinardo Sep 16, 2013 at 14:13:46 (UTC)
Goto Top
Bitte den Beitrag noch als gelöst markieren.Danke.
Grüße Uwe
Member: kontext
kontext Sep 17, 2013 at 06:31:42 (UTC)
Goto Top
Zitat von @colinardo:
Bitte den Beitrag noch als gelöst markieren.Danke.
erledigt face-wink
Grüße Uwe
Gruß
@kontext (Mod)