Hello,
I am working on a code that autofills info from Excel to PDF, saves it and then starts again.
When i start the makro the information will be filled into whatever window is opened (if this is a bug, and can be corrected, please help). Because of this, I need to make sure that the PDF File always is the one that is opened.
Sometimes, after filling the PDF with information and saving, the makro reverts back to the Excel file and starts to fill a random bracket out. This is my problem. I need the PDF to stay maximized as the makro is running, so that the information is correctly filled into the PDF, and not everywhere else.
If there is any help to be had, I will be most grateful.
Makro
Sub CreatePDFForms()
Dim PDFTemplateFile, NewPDFName, SavePDFFolder, LastName As String
Dim CustRow, LastRow As Long
Dim Navn
With Ark1
If .Range("Q18").Value = Empty Or .Range("Q20").Value = Empty Then
MsgBox "Both PDF Template and Saved PDF Locations are required for macro to run"
Exit Sub
End If
LastRow = .Range("E9999").End(xlUp).Row 'Last Row
PDFTemplateFile = .Range("Q18").Value 'Template File Name
SavePDFFolder = .Range("Q20").Value 'Save PDF Folder
ThisWorkbook.FollowHyperlink PDFTemplateFile
Application.Wait Now + 0.00006
For CustRow = 3 To LastRow
Navn = .Range("B" & CustRow).Value
Application.SendKeys "{Tab}", True
Application.SendKeys Navn, True
Application.Wait Now + 0.00001 'Navn
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("C" & CustRow).Value, True
Application.Wait Now + 0.00001 'Adresse
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("D" & CustRow).Value, True
Application.Wait Now + 0.00001 'Postadresse
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("E" & CustRow).Value, True
Application.Wait Now + 0.00001 'Epost
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("A1" & CustRow).Value, True
Application.Wait Now + 0.00001 'Konkursbo
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("I" & CustRow).Value, True
Application.Wait Now + 0.00001 'Feriepenger
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("J" & CustRow).Value, True
Application.Wait Now + 0.00001 'Feripenger
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("H" & CustRow).Value, True
Application.Wait Now + 0.00001 'Lønn
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("K" & CustRow).Value, True
Application.Wait Now + 0.00001 'Andre ytelser
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("L" & CustRow).Value, True
Application.Wait Now + 0.00001 'Skatt
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("M" & CustRow).Value, True
Application.Wait Now + 0.00001 'Skattetrekk
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("P" & CustRow).Value, True
Application.Wait Now + 0.00001 'Brutto
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("G" & CustRow).Value, True
Application.Wait Now + 0.00006 'Brutto
Application.SendKeys "^(p)", True
Application.Wait Now + 0.00003
Application.SendKeys "{Enter}", True
Application.Wait Now + 0.00003
Application.SendKeys "%(i)", True
Application.Wait Now + 0.00003
Application.SendKeys (SavePDFFolder & "\" & Navn & ".pdf")
Application.SendKeys "{Enter}", True
Application.Wait Now + 0.00009
Next CustRow
Application.SendKeys "^(q)", True
Application.SendKeys "{numlock}%s", True
End With
End Sub
I am working on a code that autofills info from Excel to PDF, saves it and then starts again.
When i start the makro the information will be filled into whatever window is opened (if this is a bug, and can be corrected, please help). Because of this, I need to make sure that the PDF File always is the one that is opened.
Sometimes, after filling the PDF with information and saving, the makro reverts back to the Excel file and starts to fill a random bracket out. This is my problem. I need the PDF to stay maximized as the makro is running, so that the information is correctly filled into the PDF, and not everywhere else.
If there is any help to be had, I will be most grateful.
Makro
Sub CreatePDFForms()
Dim PDFTemplateFile, NewPDFName, SavePDFFolder, LastName As String
Dim CustRow, LastRow As Long
Dim Navn
With Ark1
If .Range("Q18").Value = Empty Or .Range("Q20").Value = Empty Then
MsgBox "Both PDF Template and Saved PDF Locations are required for macro to run"
Exit Sub
End If
LastRow = .Range("E9999").End(xlUp).Row 'Last Row
PDFTemplateFile = .Range("Q18").Value 'Template File Name
SavePDFFolder = .Range("Q20").Value 'Save PDF Folder
ThisWorkbook.FollowHyperlink PDFTemplateFile
Application.Wait Now + 0.00006
For CustRow = 3 To LastRow
Navn = .Range("B" & CustRow).Value
Application.SendKeys "{Tab}", True
Application.SendKeys Navn, True
Application.Wait Now + 0.00001 'Navn
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("C" & CustRow).Value, True
Application.Wait Now + 0.00001 'Adresse
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("D" & CustRow).Value, True
Application.Wait Now + 0.00001 'Postadresse
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("E" & CustRow).Value, True
Application.Wait Now + 0.00001 'Epost
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("A1" & CustRow).Value, True
Application.Wait Now + 0.00001 'Konkursbo
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("I" & CustRow).Value, True
Application.Wait Now + 0.00001 'Feriepenger
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("J" & CustRow).Value, True
Application.Wait Now + 0.00001 'Feripenger
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("H" & CustRow).Value, True
Application.Wait Now + 0.00001 'Lønn
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("K" & CustRow).Value, True
Application.Wait Now + 0.00001 'Andre ytelser
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("L" & CustRow).Value, True
Application.Wait Now + 0.00001 'Skatt
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("M" & CustRow).Value, True
Application.Wait Now + 0.00001 'Skattetrekk
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("P" & CustRow).Value, True
Application.Wait Now + 0.00001 'Brutto
Application.SendKeys "{Tab}", True
Application.SendKeys .Range("G" & CustRow).Value, True
Application.Wait Now + 0.00006 'Brutto
Application.SendKeys "^(p)", True
Application.Wait Now + 0.00003
Application.SendKeys "{Enter}", True
Application.Wait Now + 0.00003
Application.SendKeys "%(i)", True
Application.Wait Now + 0.00003
Application.SendKeys (SavePDFFolder & "\" & Navn & ".pdf")
Application.SendKeys "{Enter}", True
Application.Wait Now + 0.00009
Next CustRow
Application.SendKeys "^(q)", True
Application.SendKeys "{numlock}%s", True
End With
End Sub