Send sheet as .pdf

Sub button_click()

 

Dim DataSti As String

Dim Filnavn As String

Dim objFolders As Object

Set objFolders = CreateObject(“WScript.Shell”).SpecialFolders

Dim OutlookPrg As Object

Dim OutlookMail As Object

Set OutlookPrg = CreateObject(“Outlook.Application”)

Set OutlookMail = OutlookPrg.CreateItem(0)

 

DataPath = objFolders(“desktop”) & Application.PathSeparator

Filnavn = Worksheets(“Sheet1”).Range(“D5”).Text  & “.pdf”

 

ActiveSheet.ExportAsFixedFormat _

Type:=xlTypePDF, _

Filename:=DataPath & Filnavn, _

Quality:=xlQualityStandard, _

IncludeDocProperties:=True, _

IgnorePrintAreas:=False, _

OpenAfterPublish:=False

 

On Error Resume Next

With OutlookMail

.To = Worksheets(“Sheet1”).Range(“D9”).Text

.CC = “”

.BCC = “”

.Subject = “Something- ” & Filnavn

.Body = “Hey ” &  “Kind regards” & vbCrLf & Worksheets(“Sheet1”).Range(“D3”).Text

.Attachments.Add (DataPath & Filnavn)

.Display

End With

On Error GoTo 0

 

Kill (DataPath & Filnavn)

 

Set OutlookMail = Nothing

Set OutlookPrg = Nothing

Set objFolders = Nothing

End Sub