Das nenne ich ein informatives Feedback.
Die gute Nachricht ist, dass ich die Fehlermeldung reproduzieren kann.
Folgende Zeile ist die Ursache, wenn es dieses Verzeichnis nicht gibt
Const MYPATH As String = "c:\Test\"
Wir ändern das ab. Verwenden keine Konstante sondern eine Variable.
Während der Laufzeit merken wir uns den temporären Pfad Deines Profils in dieser Variable und speichern dort die PDF.
Hier nochmal der komplette Code:
Option Explicit
Private MYPATH As String
Sub MacroMitDeinemFormularSteuerelementVerknuepfen()
Dim sText As String
MYPATH = Environ("temp")
sText = "<div>Sehr ....<br>"
sText = sText & "<p>foo bar bar foo</p>"
sText = sText & "<br>MfG</div>"
Call SendSheetOutlook( _
"Betreffzeile", _
"EMailAnZeile_als_Emailadresse_getrennt_durch_Simikolon", _
"EmailCCZeile", _
sText)
End Sub
Private Sub SendSheetOutlook(sSubject As String, sTo As String, sCC As String, ByVal sText As String)
Dim olApp As Object
Dim AWS As String
Dim olOldBody As String
'define temporary Path and Filename
AWS = MYPATH & "\" & Format(Date, "YYYYMMDD") & "_" & Format(Time, "hhmmss") & "_" & _
WorksheetFunction.Substitute(ActiveWorkbook.Name, ".xlsm", "")
'export File as PDF
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=AWS, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
AWS = AWS & ".pdf"
'Make Email
Set olApp = CreateObject("Outlook.Application")
With olApp.CreateItem(0)
.GetInspector.Display
olOldBody = .htmlBody
.To = sTo
.cc = sCC
.Subject = sSubject
.htmlBody = sText & olOldBody
.Attachments.Add AWS
End With
'remove TEMP file
'********************************
'wenn du das PDF behalten möchtest, diese Zeile auskommentieren!
'sonst wird das temporäre PDF wieder gelöscht
'Kill AWS
'********************************
End Sub
|