COMPILE ERROR: End With without With

JMAC1971

New Member
Joined
Nov 4, 2022
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
I am getting an error in this Script, but I'm not sure why... I have two With Statements and both have an EndWith. Can you please assist with what I'm missing?

I'm using the With statements to define two sheets in my File (FORM_INPUT) & (JOB_LIST)


Sub CreatePDFForms()
Dim PDFTemplateFile, NewPDFName, SavePDFFolder, DOJM As String
Dim SERVDATE
Dim DOJMRow, LastRow As Long
With Worksheets("FORM_INPUT")
PDFTemplateFile = .Range("A47").Value 'Location of Template file in spreadsheet
SavePDFFolder = .Range("E22").Value 'Saved PDF Folder

Const SW_SHOWMAXIMIZED = 3
Dim wShell As Object 'Shell32.Shell

Set wShell = CreateObject("Shell.Application")
wShell.ShellExecute "O:\Division III\Decatur Engineering\Jeff Work\Automated Job Forms\Master FORM 8-22.PDF", , , "open", SW_SHOWMAXIMIZED

Application.Wait Now + 0.00006

End With

With Worksheets("JOB_LIST")

LastRow = .Range("A9999").End(xlUp).Row

For DOJMRow = LastRow To LastRow

DOJM = .Range("A" & LastRow).Value 'DOJM
SERVTPYE = .Range("J" & LastRow).Value 'Service Type
Application.SendKeys "{Tab}", True
Application.SendKeys "{Tab}", True
Application.SendKeys "{Tab}", True
Application.SendKeys "{Tab}", True

Application.SendKeys DOJM, True 'Enter DOJM# in PDF File
Application.Wait Now + 0.00001

Application.SendKeys "{Tab}", True
Application.SendKeys .Range("C" & DOJMRow), True 'Enter Date in PDF File
Application.Wait Now + 0.00001

Application.SendKeys "{Tab}", True
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("F" & DOJMRow), True 'Enter Address in PDF File
Application.Wait Now + 0.00001

Application.SendKeys "{Tab}", True
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("H" & DOJMRow), True 'Enter County in PDF File
Application.Wait Now + 0.00001

Application.SendKeys "{Tab}", True
Application.SendKeys .Range("G" & DOJMRow), True 'Enter City in PDF File
Application.Wait Now + 0.00001

Application.SendKeys "{Tab}", True
Application.SendKeys .Range("I" & DOJMRow), True 'Enter Township in PDF File
Application.Wait Now + 0.00001

Application.SendKeys "{Tab}", True
Application.SendKeys "{Tab}", True
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("L" & DOJMRow), True 'Enter Circuit# in PDF File
Application.Wait Now + 0.00001

Application.SendKeys "{Tab}", True
Application.SendKeys .Range("M" & DOJMRow), True 'Enter Circuit Voltage in PDF File
Application.Wait Now + 0.00001

Application.SendKeys "+^(s)", True
Application.Wait Now + 0.00002
Application.SendKeys "%(n)", True
Application.Wait Now + 0.00001
Application.SendKeys SavePDFFolder & "\" & "IPCN" & DOJM & SERVTYPE & ".pdf"
Application.Wait Now + 0.00002
Application.SendKeys "%(s)", True
Application.Wait Now + 0.00002

Application.SendKeys "^(q)", True
Application.SendKeys "{numlock}%s", True

End With
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi,

you should add

Rich (BB code):
    Next
  End With
End Sub

Ciao,
Holger
 
Upvote 0
One more request... I need to format the Date entry as dd/mm/yyy but I'm getting an error. Any thoughts?

Application.SendKeys .Range("C" & DOJMRow).Format(Date, "dd/mm/yyyy"), True 'Enter Date in PDF File
 
Upvote 0
Hi JMAC1971,

maybe try

Rich (BB code):
Application.SendKeys .Range("C" & DOJMRow) & Format(Date, "dd/mm/yyyy"), True 'Enter Date in PDF File

Ciao,
Holger
 
Upvote 0
OK the only problem I'm running into is it's not carrying my date over correctly. (((.Range("C" & DOJMRow)))) - Contains a date of when a job was entered, and when I run this script it appears to be putting two dates in my pdf Form, which then gives me a validation error there since everything should be in mm/dd/yy format. Any ideas.

Application.SendKeys .Range("C" & DOJMRow) & Format(Date, "mm/dd/yy"), True 'Enter Date in PDF File

PS. Yes I did change the order of Days & Months from previous post -
 
Upvote 0
Hi JMAC1971,

if a date is located in Column C you should try

Rich (BB code):
Application.SendKeys Format(.Range("C" & DOJMRow), "mm/dd/yy"), True 'Enter Date in PDF File

Ciao,
Holger
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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