Emailing converted to PDF Worksheet

Rab_marr

New Member
Joined
Apr 12, 2016
Messages
24
Good morning all,

I found a lovely little piece of code that converts a worksheet to a PDF and emails to outlook and works perfectly for me, however the code is unique to my login identifier within the company I work for:

Sub SendSheetAsPDF()


Dim olApp As Object

Path = "C:\Users\xxxxxxxxx\Desktop" ' pls adjust
Salesman = ActiveSheet.Name
strDate = Format(Date, "ddmmyyyy")
If i > 1 Then PDF_File = Left(PDF_File, i - 1)
PDF_File = Path & Salesman & strDate & ".pdf"

With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDF_File, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With


On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err Then
Set olApp = CreateObject("Outlook.Application")
End If
On Error GoTo 0


With olApp.CreateItem(0)
.Subject = Format(Date, "yyyymmdd") & "-AinU Report-O"
.To = Range("A1")
.Body = Range("H3") & vbLf & vbLf _
& "Please find your AinU Report attached." & vbLf & vbLf _
& "Regards,"
.Attachments.Add PDF_File
.Display

End With

' if you want to delete it
'Kill PDF_File

Set olApp = Nothing

End Sub

Like I said this works a treat for me where the "xxxxxxxx" within the path is my login name.

Is there a way where "xxxxxxxxx" can be substituted for whoever is logged in at the time?

Many thanks in advance for looking into my problem

Rab
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Code:
Path=Environ("USERPROFILE") & "\Desktop"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,070
Messages
6,128,612
Members
449,460
Latest member
jgharbawi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top