Run Time Error '1004': method 'sendkeys' of object '_application' failed

won6ton

New Member
Joined
Jun 25, 2019
Messages
2
hello all,

New to this, found a random tutorial online, tried to alter it do it be useful to me. Im getting error mentioned in title. Please advise

Option Explicit


Sub PDFTemplate()
Dim PDffldr As FileDialog
Set PDffldr = Application.FileDialog(msoFileDialogFilePicker)
With PDffldr
.Title = "Select PDF file to attach"
.Filters.Add "PDF Type Files", "*.pdf", 1
If .Show <> -1 Then GoTo NoSelection
Sheet1.Range("J2").Value = .SelectedItems(1)
End With
NoSelection:
End Sub


Sub SavePDFWT()
Dim PDffldr As FileDialog
Set PDffldr = Application.FileDialog(msoFileDialogFilePicker)
With PDffldr
.Title = "Select File for W/T"
If .Show <> -1 Then GoTo NoSel:
Sheet1.Range("J5").Value = .SelectedItems(1)
End With
NoSel:
End Sub


Sub SavePDFFolder()
Dim PDffldr As FileDialog
Set PDffldr = Application.FileDialog(msoFileDialogFolderPicker)
With PDffldr
.Title = "Select Folder"
If .Show <> -1 Then GoTo NoSel:
Sheet1.Range("J8").Value = .SelectedItems(1)
End With
NoSel:
End Sub


Sub CreatePdFForms()
Dim PDFTemplateFile As String
Dim NewPDFName As String
Dim SavePDFFolder As String
Dim SavePDFWT As String
Dim JCN As String
Dim ACFTNUM As String
Dim CustRow, LastRow As Long
With Sheet1
LastRow = .Range("A9999").End(xlUp).Row
PDFTemplateFile = .Range("J2").Value
SavePDFWT = .Range("J5").Value
SavePDFFolder = .Range("J8").Value


ThisWorkbook.FollowHyperlink Address:=.Range("J2").Value, NewWindow:=False, AddHistory:=True
Application.Wait Now + 0.00006


For CustRow = 2 To 2
JCN = .Range("A" & CustRow).Value
ACFTNUM = .Range("C" & CustRow).Value
Application.SendKeys "{tab}", True
Application.SendKeys "{tab}", True
Application.SendKeys .Range("B" & CustRow).Value, True


Application.SendKeys "{tab}", True
Application.SendKeys .Range("C" & CustRow).Value, True
Application.Wait Now + 0.00003


Application.SendKeys "{tab}", True
Application.SendKeys "{tab}", True
Application.SendKeys "{tab}", True
Application.SendKeys "{tab}", True
Application.SendKeys "{tab}", True
Application.SendKeys "{tab}", True
Application.SendKeys "{tab}", True
Application.SendKeys JCN, True
Application.Wait Now + 0.00002


Application.SendKeys "{tab}", True
Application.SendKeys "{tab}", True
Application.SendKeys .Range("D" & CustRow).Value
Application.Wait Now + 0.00002


If .Range("F" & CustRow).Value <> "" Then
Application.SendKeys "{tab}", True
Application.SendKeys "{tab}", True
Application.SendKeys .Range("F" & CustRow).Value
Application.Wait Now + 0.00003
End If


ThisWorkbook.FollowHyperlink Address:=.Range("J5").Value, NewWindow:=False, AddHistory:=True
Application.Wait Now + 0.00006


Application.SendKeys "{tab}", True
Application.SendKeys .Range("A" & CustRow).Value
Application.Wait Now + 0.00002
Application.SendKeys "{tab}", True
Application.Wait Now + 0.00002


Application.SendKeys "^+(s)", True
Application.SendKeys "%(n)", True
Application.Wait Now + 0.00002


Application.SendKeys SavePDFFolder & "" & JCN & ".pdf"
Application.Wait Now + 0.00002
Application.SendKeys "%(s)", True
Application.Wait Now + 0.00002




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

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
apologies, should have provided a little more info.
it opens the save as screen but doesnt input file name and it just stops there.
 
Upvote 0

Forum statistics

Threads
1,223,887
Messages
6,175,199
Members
452,617
Latest member
Narendra Babu D

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