Macro to email excel file as PDF to a specific email address using any email server

rschmidt

New Member
Joined
Jul 28, 2015
Messages
11
Good Morning Helpful Excel Peeps

I have an excel file that will be posted on a website for an individual to fill out. I want them to click a button (which I have created) and email the excel file to a specific email address.
I have created this but my problem is, that the macro I am using only wants to send through Outlook and not everyone has outlook.

Here is the Macro I came up with. Any help would be greatly appreciated


VBA Code:
Sub EmailRegistration()
Dim oApp As Object
   Dim oMail As Object
   Dim LWorkbook As Workbook
   Dim LFileName As String
  
   'Turn off screen updating
   Application.ScreenUpdating = False
  
   'Copy the active worksheet and save to a temporary workbook
   ActiveSheet.Copy
   Set LWorkbook = ActiveWorkbook
  
   'Create a temporary file in your current directory that uses the name
   ' of the sheet as the filename
   LFileName = LWorkbook.Worksheets(1).Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")
   On Error Resume Next
   'Delete the file if it already exists
   Kill LFileName
   On Error GoTo 0
   'Save temporary file
   LWorkbook.SaveAs Filename:=LFileName
  
   'Create an Outlook object and new mail message
   Set oApp = CreateObject("Outlook.Application")
   Set oMail = oApp.CreateItem(0)
  
   'Set mail attributes (uncomment lines to enter attributes)
   ' In this example, only the attachment is being added to the mail message
   With oMail
      .To = "EMAIL ADDRESS GOES HERE"
      .Subject = "Endless Dulcimer Registration 2022"
      .body = "Please see the attached completed registration for the upcoming event." & vbCrLf & vbCrLf & _
      "Attached is the file"
      .Attachments.Add LWorkbook.FullName
      .Display
   End With
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Correction - doesn't have to end up as a PDF file. the macro I created is just emailing the spreadsheet with a date at the end.
 

Attachments

  • Screenshot 2022-05-02 122428.png
    Screenshot 2022-05-02 122428.png
    66.9 KB · Views: 10
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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