Udskriv fra Excel pdf-fil og vedhæft outlook
Denne rutine (fundet her på Eksperten og nødtørftigt tilpasset) fungerer, men udskriver hele fanebladets indhold. Jeg ønsker imidlertid kun et bestemt område (døbt Print_Area omfattende cellerne A68:F120). Hvor og hvad taster jeg ind i følgende makro?:Sub CreatePDF_attach_to_EMAIL()
Dim Wkb As String
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Object
Dim OutMail As Object
Wkb = ThisWorkbook.Name
TempFilePath = Environ$("temp") & "\"
TempFileName = TempFilePath & Wkb & ".pdf"
Worksheets("euroinvoice").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
TempFileName, Quality:= _
xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.Display
End With
Signature = OutMail.body 'gets the email's standard signature
On Error Resume Next
With OutMail
.To = "" 'can instead be linked to a cell in the excel sheet
.CC = ""
.BCC = ""
.Subject = "Cost status report - " & ActiveWorkbook.Worksheets("Dev Report").Range("D5") & " - " & ActiveWorkbook.Worksheets("Dev Report").Range("D4") & " - " & ActiveWorkbook.Worksheets("Dev Report").Range("R4")
.body = "Hi" & Chr(10) & Chr(10) & "Please find attached cost status report for " & ActiveWorkbook.Worksheets("Dev Report TEST").Range("D4") & " at end of " & ActiveWorkbook.Worksheets("Dev Report TEST").Range("R4") & Chr(10) & Signature
.Attachments.Add TempFileName
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
If Dir(TempFileName) <> "" Then Kill TempFileName 'deletes the created PDF file in the temps-folder
Sub email()
'
' email Makro
'Sub CreatePDF_attach_to_EMAIL()
Dim Wkb As String
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Object
Dim OutMail As Object
Wkb = ThisWorkbook.Name
TempFilePath = Environ$("temp") & "\"
TempFileName = TempFilePath & Wkb & ".pdf"
Worksheets("euroinvoice").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
TempFileName, Quality:= _
xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.Display
End With
Signature = OutMail.body 'gets the email's standard signature
On Error Resume Next
With OutMail
.To = "" 'can instead be linked to a cell in the excel sheet
.CC = ""
.BCC = ""
.Subject = "Cost status report - " & ActiveWorkbook.Worksheets("Dev Report").Range("D5") & " - " & ActiveWorkbook.Worksheets("Dev Report").Range("D4") & " - " & ActiveWorkbook.Worksheets("Dev Report").Range("R4")
.body = "Hi" & Chr(10) & Chr(10) & "Please find attached cost status report for " & ActiveWorkbook.Worksheets("Dev Report TEST").Range("D4") & " at end of " & ActiveWorkbook.Worksheets("Dev Report TEST").Range("R4") & Chr(10) & Signature
.Attachments.Add TempFileName
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
If Dir(TempFileName) <> "" Then Kill TempFileName 'deletes the created PDF file in the temps-folder
'
ActiveCell.Offset(12, 1).Range("A1").Select
ActiveWindow.SmallScroll Down:=60
ActiveCell.Offset(55, -4).Range("A1").Select
Application.Goto Reference:="Print_Area"
ActiveWindow.SmallScroll Down:=-72
End Sub