Sub TT()
Dim Co_Id As String, xTable As Object, Sh As Worksheet, R As Integer, C As Integer, i As Integer, ii As Integer
'Co_Id = stock_no
Co_Id = InputBox("Input Stock No")
Do While .Busy Or .readyState <> 4: DoEvents: Loop '等候網頁宰入完整
.Document.ALL("query-button").Click '網頁上按下查詢鍵
Do While .Busy Or .readyState <> 4: DoEvents: Loop '等候網頁宰入完整
Set xTable = .Document.ALL.TAGS("Table") '設定變數為網頁 tagname "Table"的物件集合
'***這段程式碼供尋找第幾個Table為所你要的資料**
'For i = 0 To xTable.Length - 1? ?'Length 網頁物件集合計算子物件的函數
'MsgBox "第" & i & "個資料" & vbLf & xTable(i).innertext '**查看你要的資料為第幾個Table
' Next
'************************************
Set Sh = Sheets("temp") '指定工作頁
Sh.UsedRange.Clear '清除工作頁
'*******讀取資料的程式碼******************
ii = 1
For i = 3 To 4
If InStr(xTable(i).innertext, "查無資料!") Then MsgBox xTable(i).innertext: .Quit: Exit Sub
For R = 0 To xTable(i).Rows.Length - 1
For C = 0 To xTable(i).Rows(R).Cells.Length - 1
Sh.Cells(R + ii, C + 1) = xTable(i).Rows(R).Cells(C).innertext
Next
Next
ii = R + 2
Next
'****************************************************
With Sh
Co_Id = .[a1]
.[a1] = ""
.UsedRange.Columns.AutoFit '**AutoFit 方法 將範圍中的欄寬和列高調整為最適當的值。
.[a1] = Co_Id
End With
.Quit '關閉網頁
End With
End Sub
執行後出現錯誤在 If InStr(xTable(i).innertext, "查無資料!") Then MsgBox xTable(i).innertext: .Quit: Exit Sub
請那語法有誤 ? 謝謝作者: GBKEE 時間: 2017-3-11 13:59