bmsolutions
New Member
- Joined
- May 9, 2022
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
Hi everyone,
I am a complete novice when it comes to macros and VBA, but after following a YouTube tutorial I have managed to put together a macro which creates a PDF of the current sheet, and creates an email with said PDF attached.
Here is the code:
Ideally, I would like to point this towards a Sharepoint folder (it technically currently is, but it's pointed towards my local version of the Sharepoint folder, rather than to the online folder). If anyone else uses the macro it doesn't work because there username, and there local version of the same Sharepoint folder follows a different file path.)
I've read many similar questions on this forum and tried implementing various solutions but keep running into errors and I'm afraid due to my lack of coding skills I don't have the know how to fix these errors to get this working.
Any help would be much appreciated! Thanks!
I am a complete novice when it comes to macros and VBA, but after following a YouTube tutorial I have managed to put together a macro which creates a PDF of the current sheet, and creates an email with said PDF attached.
Here is the code:
The problem I am having is this only works for me as the user INSERTUSERNAMEHERE (I've anonymised this along with the folder names.)Sub EmailasPDF()
Dim EApp As Object
Set EApp = CreateObject("Outlook.Application")
Dim EItem As Object
Set EItem = EApp.CreateItem(0)
Dim advisername As String
Dim invoicedate As String
Dim path As String
Dim fname As String
advisername = Range("B10")
invoicedate = Range("A9")
path = "C:\Users\INSERTUSERNAMEHERE\MISC FOLDER NAME\MISC FOLDER NAME 2\MISC FOLDER NAME 3\MISC FOLDER NAME 4\MISC FOLDER NAME 5\MISC FOLDER NAME 6"
fname = " " & advisername & " " & invoicedate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, IgnorePrintAreas:=False, Filename:=path & fname
With EItem
.To = Range("G16")
.Subject = advisername & " " & invoicedate
.Body = "Please find invoice attached."
.Attachments.Add (path & fname & ".pdf")
.Display
End With
End Sub
Ideally, I would like to point this towards a Sharepoint folder (it technically currently is, but it's pointed towards my local version of the Sharepoint folder, rather than to the online folder). If anyone else uses the macro it doesn't work because there username, and there local version of the same Sharepoint folder follows a different file path.)
I've read many similar questions on this forum and tried implementing various solutions but keep running into errors and I'm afraid due to my lack of coding skills I don't have the know how to fix these errors to get this working.
Any help would be much appreciated! Thanks!