Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1836to1840
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

VBA Tabellenblatt als pdf UND xls mailen

VBA Tabellenblatt als pdf UND xls mailen
24.06.2021 15:47:41
Lisi
Hallo,
ich möchte gerne mittels VBA-Script aus Excel das aktive Tabellenblatt als Mailanhang (als pdf UND xlsx) verschicken. Die Anhänge sollen nur temporär abgespeichert werden. Die Daten des Excel-Anhangs sollen nur als Werte eingefügt werden.
Leider schaffe ich es nur ein pdf anzuhängen. Am zweiten Anhang scheitere trotz stundenlanger Recherche.
Ich hoffe, dass mir jemand weiterhelfen kann.
Vielen Dank vorab!
LG Lisi

3
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: VBA Tabellenblatt als pdf UND xls mailen
25.06.2021 12:34:17
migre
Hallo!
Bspw. so:
Option Explicit

Sub AktivesBlattAlsExcelUndPdfMailen()
Dim Wb As Workbook: Set Wb = ThisWorkbook
Dim Ws As Worksheet: Set Ws = Wb.ActiveSheet
Dim WbCopy As Workbook, WsCopy As Worksheet
Dim clc, XLpfad As String, PDFpfad As String
Dim OutlookApp As Object
Dim OutlookEmail As Object
Dim IsCreated As Boolean
With Application
clc = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
On Error Resume Next
Set OutlookApp = GetObject(, "Outlook.Application")
If Err Then
Set OutlookApp = CreateObject("Outlook.Application")
IsCreated = True
End If
On Error GoTo 0
If IsCreated Then OutlookApp.Quit
With Application
.Calculation = clc
.ScreenUpdating = True
End With
With Ws
.Copy
Set WbCopy = ActiveWorkbook
Set WsCopy = WbCopy.Sheets(1)
WsCopy.UsedRange.Value = WsCopy.UsedRange.Value
WbCopy.SaveAs Wb.Path & "\" & "Emailversand", 51
XLpfad = WbCopy.FullName
WbCopy.Close True
PDFpfad = Wb.Path & "\" & "Emailversand" & ".pdf"
Ws.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=PDFpfad, _
quality:=xlQualityStandard, _
includedocproperties:=True, _
ignoreprintareas:=False, _
openafterpublish:=False
Set OutlookEmail = OutlookApp.createitem(0)
With OutlookEmail
.Subject = "Betreff"
.To = "max@muster.de"
.CC = "moritz@probe.de"
.Body = "Hier kommt die Tabelle..."
.attachments.Add XLpfad
.attachments.Add PDFpfad
.display
End With
Kill XLpfad
Kill PDFpfad
End With
If IsCreated Then OutlookApp.Quit
With Application
.Calculation = clc
.ScreenUpdating = True
End With
Set Wb = Nothing: Set Ws = Nothing: Set WbCopy = Nothing
Set WsCopy = Nothing: Set OutlookApp = Nothing: Set OutlookEmail = Nothing
End Sub
Bsp-Mappe: https://www.herber.de/bbs/user/146798.xlsm
LG
Michael
Anzeige
AW: VBA Tabellenblatt als pdf UND xls mailen
29.06.2021 15:14:56
Lisi
Perfekt...es hat funktioniert. Vielen Dank!
Gern, Danke für die Rückmeldung, owT
29.06.2021 23:05:29
migre

321 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige