在vba excel中input不匹配错误

我有一个单独运行的代码(使用F8键),我可以得到输出。 而如果我运行使用F5它显示types不匹配错误。 如何解决它。 程序供您参考:

Sub Getting_BOM() Sheets("DATA").Range("a6:F1000").ClearContents 'Launching Web Page Set ie = CreateObject("InternetExplorer.Application") ie.Visible = True URL = "http://home.gsi.local/VBGSIWeb/Production/PackingList.aspx" ie.Navigate2 URL Do While ie.ReadyState <> 4 DoEvents Loop Do While ie.Busy = True DoEvents Loop pnumber = Sheets("DATA").Range("B2").Value Sheets("DATA").Select If pnumber <> "" Then Do While ie.Busy = True DoEvents Loop Set search_box = ie.document.getelementbyid("txtItem") search_box.Value = pnumber Do While ie.Busy = True DoEvents Loop If search_box Is Nothing Then MsgBox "Connect GSI Cisco first !!!", vbCritical, "GSI Cisco Problem" Shell "C:\Program Files\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe", vbNormalFocus ie.Quit Sheets("DATA").Select Exit Sub End If Set table_val = ie.document.getelementbyid("lblPackListDescription") Do While ie.Busy = True DoEvents Loop Set search_Button = ie.document.getelementbyid("btnSearch") search_Button.Click ' IE.Visible = True Application.Wait (Now + TimeValue("0:00:04")) Set Table_header = ie.document.getelementbyid("lblPackListDescription") If errno > 5 Then Sheets("DATA").Range("d6").Value = "Invalid Item Number" errno = 0 Err.Clear GoTo Here End If If Table_header.innertext = 0 Then Err.Clear GoTo Here End If If Err Then errno = errno + 1 Err.Clear GoTo there End If there: n = 5 For i = 6 To 300 **Set table_val = ie.document.getelementbyid("dgPacklist")**(here it shows as error) availability = 0 nn = (i - 5) components = table_val.Cells(nn * (11 + availavlity)).innertext If components = " " Then Exit For n = n + 1 Range("B" & n).Select Sheets("DATA").Range("a" & n).Value = (i - 5) Description_val = table_val.Cells((nn * (11 + availability)) + 1).innertext qty_val = table_val.Cells((nn * (11 + availability)) + 2).innertext Sheets("DATA").Range("B" & n).Value = Mid(components, 1, 500) Sheets("DATA").Range("C" & n).Value = qty_val Next i End If Call Module1.Part_Long_Description Call Module1.Paste_Description 'Call Module1.SaveAs_CSV MsgBox "Task Finished", vbInformation, "Finished" Here: ie.Quit End Sub