我有一个子来填写pdf,具体取决于哪个元素。第一个子例程是实际打开pdf并向其中填充信息的例程。第二个子实际上是根据要读取的元素找到要运行的子。
第二个子句的最后一行是我试图调用第一个子句的地方。这总是会引发错误[400]。
以下代码是我的第一个子例程:
Sub FSCEIEO()
Dim PDFTemplateFile, NewPDFName, SavePDFFldr, Desc As String
Dim CustRow, LastRow As Long
With Sheet2
D1 = .Range("AB" & CustRow).Value & "'' Diameter x " & .Range("AD" & CustRow).Value & "''"
D2 = .Range("AS" & CustRow).Value
D3 = .Range("AZ" & CustRow).Value & " lbs"
D4 = .Range("S" & CustRow).Value
D5 = .Range("AO" & CustRow).Value & "''"
D6 = .Range("AR" & CustRow).Value & "''"
D7 = .Range("AP" & CustRow).Value & "''"
D8 = .Range("AK" & CustRow).Value & "''"
Description = D4
DataEntry = Array(D1, D2, D3, D4, D5, D6, D7, D8)
For Each e In DataEntry
Application.SendKeys "{Tab}", True
Application.SendKeys e, True
Application.Wait Now + 0.00001
Next e
Application.SendKeys "{Tab}", True
Application.SendKeys "{Esc}", True
Application.SendKeys "^(p)", True
Application.Wait Now + 0.00001
Application.SendKeys "{Tab}", True
Application.SendKeys "{Enter}", True
Application.Wait Now + 0.00001
Application.SendKeys "{l}", True
Application.SendKeys "{Enter}", True
Application.Wait Now + 0.00001
Application.SendKeys "{Left}", True
Application.SendKeys "{Enter}", True
Application.SendKeys "{Enter}", True
Application.Wait Now + 0.00001
If Dir(SavePDFFldr & "\" & Description & ".pdf") <> Empty Then Kill (SavePDFFldr & "\" & Description & ".pdf")
Application.SendKeys SavePDFFldr & "\" & Description & ".pdf"
Application.Wait Now + 0.00001
Application.SendKeys "%(s)"
Application.Wait Now + 0.00001
Application.SendKeys "^(q)", True
Application.SendKeys "{numlock}%s", True
Application.SendKeys "{Tab}", True
Application.SendKeys "{Enter}", True
End With
End Sub
我的第二个子内容如下:
Sub CreateDrawings()
Dim PDFTemplateFile, NewPDFName, SavePDFFldr, Desc As String
Dim CustRow, LastRow As Long
LastRow = Sheet2.Range("A999").End(xlUp).Row
'''''''''''''''''''''''''''''''''''''''''''' PDF TEMPLATES ''''''''''''''''''''''''''''''''''''''''''''''''''''
PDFTemplateFile1 = Sheet4.Range("BU3").Value ' FSC EIEO
PDFTemplateFile2 = Sheet4.Range("BU4").Value ' FSC EISO
PDFTemplateFile3 = Sheet4.Range("BU5").Value ' FSC SIEO
PDFTemplateFile4 = Sheet4.Range("BU6").Value ' FSC SISO
PDFTemplateFile5 = Sheet4.Range("BU7").Value ' NBG
PDFTemplateFile6 = Sheet4.Range("BU8").Value ' RAIN CAPS
PDFTemplateFile7 = Sheet4.Range("BU9").Value ' CPMS Single
PDFTemplateFile8 = Sheet4.Range("BU10").Value ' CPMS Dual
PDFTemplateFile9 = Sheet4.Range("BU11").Value ' Expansion Joint
PDFTemplateFile10 = Sheet4.Range("BU12").Value
PDFTemplateFile11 = Sheet4.Range("BU13").Value
PDFTemplateFile12 = Sheet4.Range("BU14").Value
PDFTemplateFile13 = Sheet4.Range("BU15").Value
PDFTemplateFile14 = Sheet4.Range("BU16").Value
PDFTemplateFile15 = Sheet4.Range("BU17").Value
PDFTemplateFile16 = Sheet4.Range("BU18").Value
SavePDFFldr = Sheet2.Range("Q47").Value
With Sheet2
For CustRow = 5 To 6
Application.Wait Now + 0.00001
'''''''''''''''''''''''''''''''''''''''''''' FSC EIEO ''''''''''''''''''''''''''''''''''''''''''''''''''''
If InStr(Sheet2.Range("R" & CustRow), "FSC") > 0 Then
If Sheet2.Range("AQ" & CustRow) = "EIEO" Then
ThisWorkbook.FollowHyperlink PDFTemplateFile1
Application.Wait Now + 0.00001
FSCEIEO
End With
End Sub
答案 0 :(得分:1)
Sub firstSub()
MsgBox "OK"
End Sub
Sub secondSub()
Application.Run "firstSub"
End Sub
使用Application.Run "yourSub"
运行另一个子,如果子在另一个模块中,则使用Application.Run "yourModule.YourSub"
您的代码可能是这样的:
With Sheet2
For CustRow = 5 To 6
Application.Wait Now + 0.00001
'''''''''''''''''''''''''''''''''''
If InStr(Sheet2.Range("R" & CustRow), "FSC") > 0 Then
If Sheet2.Range("AQ" & CustRow) = "EIEO" Then
ThisWorkbook.FollowHyperlink PDFTemplateFile1
Application.Wait Now + 0.00001
Application.Run "FSCEIEO" '
'If your Sub is in another module
'Application.Run "ModuleName.FSCEIEO"
End if 'Change this part
End If 'Your missing this closing IF
End With 'Check your closing tags
也许错误[400]可能是因为缺少了End If
关于Application.Run
,即使te SUB
被定义为Private
,也可以使用它(称为子)。有关更多信息,请参见此:Data Pipeline Pricing