Calling a String

oliquino

New Member
Joined
Apr 16, 2020
Messages
9
Office Version
  1. 2016
  2. 2013
  3. 2010
Platform
  1. Windows
I have set Dim NewPDFFile As String however it doesn't push and call the path which needs to be inserted on the dialog box.

NewPDFFile As String

NewPDFFile = ThisWorkbook.Path & "\" & StudentName & "_Enrollment.pdf" 'New File Name
If Dir(NewPDFFile, vbDirectory) <> "" Then Kill (NewPDFFile) 'Deleted File if exists


........

Application.SendKeys "+^(s)", True
Application.Wait Now + 0.00001
Application.SendKeys "^~", True
Application.Wait Now + 0.00001

Application.SendKeys NewPDFFile, True
Application.Wait Now + 0.00002

End Sub


1587381297395.png
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
ThisWorkbook.Path is null if the workbook has not been saved,

and here's some better functions:
if FileExists(sFile) then KillFile(sFile)
but with this function you dont have to do the IF FILEEXISTS,
just run: KillFile(sFile), if its there it deletes, if not , it moves on.

Code:
Public Function FileExists(ByVal pvFile) As Boolean
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
FileExists = FSO.FileExists(pvFile)
Set FSO = Nothing
End Function

Public Sub KillFile(ByVal pvFile)
Dim FSO
On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject")
'FileReadOnly pvFile, False
FSO.DeleteFile pvFile
Set FSO = Nothing
End Sub
 
Upvote 0
Thank you ranman256. here is the actual code shared to me and appreciate if how code shared will be added on the existing macro. thank you.

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
 
Upvote 0

Forum statistics

Threads
1,215,234
Messages
6,123,776
Members
449,123
Latest member
StorageQueen24

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