Filling Up PDF, Saving and Sending on Email

oliquino

New Member
Joined
Apr 16, 2020
Messages
9
Office Version
  1. 2016
  2. 2013
  3. 2010
Platform
  1. Windows
Hi guys,

Having challenges with the macro that was shared to me. It works as to filing up the PDF however 1) it doesn't go through on saving when codes for Email is included 2) New File name set was not followed.

Sub FillWorkshopPDFForm()
Dim PDFTemplateFile As String, NewPDFFile As String, SavePDFFolder As String, StudentName As String
Dim Subj As String, Mesg As String, EmailAdd As String
Dim StudentRow As Long, LastRow As Long
Dim OutApp As Object, OutMail As Object

If Sheet1.Range("E5").Value = Empty Then
MsgBox "Please select a PDF Template to use"
SetPDFTemplate
If Sheet1.Range("E5").Value = Empty Then Exit Sub
End If
PDFTemplateFile = Sheet1.Range("E5").Value 'Template File Name

With Sheet2
LastRow = .Range("A9999").End(xlUp).Row 'Last Student Row
ThisWorkbook.FollowHyperlink PDFTemplateFile
Application.Wait Now + 0.00002

For StudentRow = 3 To LastRow
If .Range("H" & StudentRow).Value = Empty Then
StudentName = .Range("A" & StudentRow).Value 'Student Name
EmailAdd = .Range("F" & StudentRow).Value 'Email Address
Subj = Replace(Sheet1.Range("E7").Value, "#Name#", StudentName) 'Email Subject
Mesg = Replace(Sheet1.Range("E9").Value, "#Name#", StudentName) 'Email Message
NewPDFFile = ThisWorkbook.Path & "\" & StudentName & "_Enrollment.pdf" 'New File Name
If Dir(NewPDFFile, vbDirectory) <> "" Then Kill (NewPDFFile) 'Deleted File if exists

'Clear Form
Application.Wait Now + 0.00001
Application.SendKeys "%"
Application.Wait Now + 0.00001
Application.SendKeys "M"
Application.Wait Now + 0.00001
Application.SendKeys "F"
Application.Wait Now + 0.00001

'Add fields
Application.SendKeys "{Tab}", True
Application.SendKeys StudentName, True
Application.Wait Now + 0.00001
Application.SendKeys "{Tab}", True
Application.SendKeys EmailAdd, True
Application.Wait Now + 0.00001
Application.SendKeys "{Tab}", True
Application.SendKeys Format(.Range("G" & StudentRow).Value, "###-###-####"), True 'Phone #
Application.Wait Now + 0.00001
Application.SendKeys "^+(s)", True
Application.Wait Now + 0.00001
Application.SendKeys NewPDFFile, True
Application.Wait Now + 0.00002
Application.SendKeys "%(s)" 'Save As
Application.Wait Now + 0.00002

'Create Emaiol
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = EmailAdd
.Subject = Subj
.Body = Mesg
.Attachments.Add NewPDFFile
If Sheet1.Range("B5").Value = True Then .Display Else .Send 'Send or Display Email
End With
.Range("H" & StudentRow).Value = Now 'Set Current Date & Time
AppActivate "Foxit Reader"

End If
Next StudentRow
Application.SendKeys "^(q)", True
Application.SendKeys "{numlock}%s", True
End With

End Sub


1587317503514.png


1587317528009.png


Appreciate help. Thank you
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Watch MrExcel Video

Forum statistics

Threads
1,130,029
Messages
5,639,623
Members
417,101
Latest member
amoverton2

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
Top