VBA PDF and Mailto Help!!

delts509

New Member
Joined
Sep 30, 2016
Messages
5
Good evening,

I am working on a Macro that is going to compile a form into a PDF and email it to a person within our institution. I currently have it working correctly to generate the email and get the active sheet turned into a PDF, but I need the PDF to also include another workbook that is full of upfront data. Is there a way/code that I can use to generate a PDF for two open workbook tabs? If it helps, the first workbook will always be called 'Materials Selection', and then the active page will be one of several choices.

Here is the code that I am currently using, can this be modified to achieve what I have above?

Sub sendReminderMailConsult()
ChDir "C:\Users" & Environ("Username") & "\Desktop"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users" & Environ("Username") & "\Desktop\Materials Request Form_" & Format(Now, "mm-dd-yyyy_hhmm") & ".pdf", OpenAfterPublish:=True


Dim OutLookApp As Object
Dim OutLookMailItem As Object
Dim myAttachments As Object


Set OutLookApp = CreateObject("Outlook.application")
Set OutLookMailItem = OutLookApp.CreateItem(0)
Set myAttachments = OutLookMailItem.Attachments


With OutLookMailItem
.To = "Insert.name@institution.edu"
.Subject = "Materials Selection Form Submission"
.Body = "Please see the attached materials selection form for your review."
myAttachments.Add "C:\Users" & Environ("Username") & "\Desktop\Materials Request Form_" & Format(Now, "mm-dd-yyyy_hhmm") & ".pdf"
'.send
.Display
End With


Set OutLookMailItem = Nothing
Set OutLookApp = Nothing




End Sub

Thank you for your help!!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Here are two ways
Rich (BB code):
Worksheets(Array("Materials Selection", "NewSheet")).Select

or

Worksheets(Array("Materials Selection", ActiveSheet.Name)).Select

So your code might look like this
Rich (BB code):
Sub sendReminderMailConsult()
Worksheets(Array("Materials Selection", ActiveSheet.Name)).Select
ChDir "C:\Users" & Environ("Username") & "\Desktop"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users" & Environ("Username") & "\Desktop\Materials Request  Form_" & Format(Now, "mm-dd-yyyy_hhmm") & ".pdf",  OpenAfterPublish:=True

Although it does look like you are missing some slashes, but if it works for you though 'cos code would be
Rich (BB code):
"C:\Users\" & Environ("Username") & "\Desktop"
 
Last edited:
Upvote 0
That actually worked perfectly for me (I adjusted the form name in the VBA), but I sent it to a coworker to try (she is on a Mac), and she is receiving an error when the macro runs. The error she receives says the following:

The Macro "Macintosh HD:Users:JaneSmith:Library:Caches:TemopraryItems:Outlook Temp:Large Cost Materials Evaluation Form[1].xlsm'! sendreminderMailconsult cannot be found.

Here is the full code that I am using:

Sub sendReminderMailConsult()
Worksheets(Array("Materials Selection", ActiveSheet.Name)).Select
ChDir "C:\Users" & Environ("Username") & "\Desktop"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users" & Environ("Username") & "\Desktop\Large Cost Materials Evaluation Form_" & Format(Now, "mm-dd-yyyy_hhmm") & ".pdf", OpenAfterPublish:=True


Dim OutLookApp As Object
Dim OutLookMailItem As Object
Dim myAttachments As Object


Set OutLookApp = CreateObject("Outlook.application")
Set OutLookMailItem = OutLookApp.CreateItem(0)
Set myAttachments = OutLookMailItem.Attachments


With OutLookMailItem
.To = "John.Smith@Collegestation.edu"
.Subject = "Materials Selection Form Submission"
.Body = "Please see the attached materials selection form for your review."
myAttachments.Add "C:\Users" & Environ("Username") & "\Desktop\Large Cost Materials Evaluation Form_" & Format(Now, "mm-dd-yyyy_hhmm") & ".pdf"
'.send
.Display
End With


Set OutLookMailItem = Nothing
Set OutLookApp = Nothing




End Sub

Any thoughts on what I am doing wrong here?

Thank you!!
 
Upvote 0
Glad it worked on the windows

I don't use a MAC, so i really cant say.

How are the file paths on MACS, similar to windows? Thats what you need to check
 
Upvote 0

Forum statistics

Threads
1,214,553
Messages
6,120,176
Members
448,948
Latest member
spamiki

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