Hi
I am looking for a VBA code that will save an excel file in a specified folder as a PDF based on cell values and then open an email with pre defined email addresses and subject/body based on text/cell values. Does such code exist?
Thanks
Anthony
Hi
I am looking for a VBA code that will save an excel file in a specified folder as a PDF based on cell values and then open an email with pre defined email addresses and subject/body based on text/cell values. Does such code exist?
Thanks
Anthony
Attaching a sample workbook enables others to work on your problem:
To attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include BEFORE/AFTER sheets if needed to show the process you're trying to complete or automate. Remember to desensitize the data.
Click on GO ADVANCED and click "manage attachments" to open the upload window.
-
See clip
To add a file to a post
Thanks - see attached example.
Essentially I would like the file to be named and saved as: Collection/Return Request - (Cell C12 value) - (Cell C7 value)
Then click the send request to email button will attach the PDF to the email...
And then then the subject of the email to be the same as the file name.
The body of the email to say:
Please find attached return request form.
Regards
(Cell C8) value)
Thanks
Anthony
Thanks - see attached example.
Essentially I would like the file to be named and saved as: Collection/Return Request - (Cell C12 value) - (Cell C7 value)
Then click the send request to email button will attach the PDF to the email...
And then then the subject of the email to be the same as the file name.
The body of the email to say:
Please find attached return request form.
Regards
(Cell C8) value)
Thanks
Anthony
For starters.
![]()
Sub tst() With Sheet1 fName = "Collection_Return Request - " & .Range("C12") & " - " & Replace(.Range("C7"), "/", "_") .ExportAsFixedFormat 0, ThisWorkbook.Path & Application.PathSeparator & fName End With With CreateObject("outlook.application").createitem(0) .to = "emailaddress here" .Subject = fName .body = "Please find the attached return request form." & vbLf & vbLf & _ "Regards." & vbLf & vbLf & _ Sheet1.Range("C8") .attachments.Add ThisWorkbook.Path & Application.PathSeparator & fName & ".pdf" .display End With 'remove following line if you want to keep pdf-file Kill ThisWorkbook.Path & Application.PathSeparator & fName & ".pdf" End Sub
Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.
That is spot on, the only other thing I would need is to save the PDF in a specific folder on a shared drive. Could this be added?
Thanks again
Last edited by davesexcel; 02-21-2019 at 06:37 AM.
Try replacing the red part with the shared drive path.![]()
.ExportAsFixedFormat 0, ThisWorkbook.Path & Application.PathSeparator & fName
Thanks again, whereabouts in the string should this go?
As I said replace the red part.
![]()
.ExportAsFixedFormat 0, "shared_folder_path_here" & Application.PathSeparator & fName
I meant where in the bit below it should go...?
![]()
Sub tst() With Sheet1 fName = "Collection_Return Request - " & .Range("C12") & " - " & Replace(.Range("C7"), "/", "_") .ExportAsFixedFormat 0, ThisWorkbook.Path & Application.PathSeparator & fName End With With CreateObject("outlook.application").createitem(0) .to = "emailaddress here" .Subject = fName .body = "Please find the attached return request form." & vbLf & vbLf & _ "Regards." & vbLf & vbLf & _ Sheet1.Range("C8") .attachments.Add ThisWorkbook.Path & Application.PathSeparator & fName & ".pdf" .display End With 'remove following line if you want to keep pdf-file Kill ThisWorkbook.Path & Application.PathSeparator & fName & ".pdf" End Sub
![]()
Sub tst() With Sheet1 fName = "Collection_Return Request - " & .Range("C12") & " - " & Replace(.Range("C7"), "/", "_") .ExportAsFixedFormat 0, "CHANGE THIS TO THE PATH" & Application.PathSeparator & fName End With With CreateObject("outlook.application").createitem(0) .to = "emailaddress here" .Subject = fName .body = "Please find the attached return request form." & vbLf & vbLf & _ "Regards." & vbLf & vbLf & _ Sheet1.Range("C8") .attachments.Add "CHANGE THIS TO THE PATH" & Application.PathSeparator & fName & ".pdf" .display End With 'remove following line if you want to keep pdf-file Kill "CHANGE THIS TO THE PATH" & Application.PathSeparator & fName & ".pdf" End Sub
Last edited by banaanas; 02-21-2019 at 07:36 AM. Reason: Added missing points
And also.
Or in 1 go.![]()
Sub tst() With Sheet1 fName = "Collection_Return Request - " & .Range("C12") & " - " & Replace(.Range("C7"), "/", "_") .ExportAsFixedFormat 0, "CHANGE THIS TO THE PATH" & Application.PathSeparator & fName End With With CreateObject("outlook.application").createitem(0) .to = "emailaddress here" .Subject = fName .body = "Please find the attached return request form." & vbLf & vbLf & _ "Regards." & vbLf & vbLf & _ Sheet1.Range("C8") .attachments.Add ThisWorkbook.Path & Application.PathSeparator & fName & ".pdf" .display End With 'remove following line if you want to keep pdf-file Kill ThisWorkbook.Path & Application.PathSeparator & fName & ".pdf" End Sub
![]()
Sub tst() mypath = "CHANGE THIS TO THE PATH" With Sheet1 fName = "Collection_Return Request - " & .Range("C12") & " - " & Replace(.Range("C7"), "/", "_") .ExportAsFixedFormat 0, mypath & Application.PathSeparator & fName End With With CreateObject("outlook.application").createitem(0) .to = "emailaddress here" .Subject = fName .body = "Please find the attached return request form." & vbLf & vbLf & _ "Regards." & vbLf & vbLf & _ Sheet1.Range("C8") .attachments.Add mypath & Application.PathSeparator & fName & ".pdf" .display End With 'remove following line if you want to keep pdf-file Kill mypath & Application.PathSeparator & fName & ".pdf" End Sub
Last edited by bakerman2; 02-21-2019 at 07:32 AM.
Perfect thanks for all your help on this!!!
Glad to help and thanks for rep+.
If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks