返回列表 上一主題 發帖

[發問] VBA控制IE輸入值

[發問] VBA控制IE輸入值

請問VBA神人:
要如何控制IE的值在VBA直接輸入就好?
以下是我模仿的程式,地區輸入: 104 ,
執行到Set what = .document.getElementByName("onchage")
就出現錯誤訊息,可是不知道怎麼改,請問有大大可以協助嗎??

Sub Ex_網頁元素_3()

Dim E As Object, what As Object

Set objIE = CreateObject("InternetExplorer.application")
URL = "http://amis.afa.gov.tw/v-htm/v102.htm"

myjobtype = InputBox("輸入地區代號:")

With objIE
    .Visible = True
    .Navigate URL
    Do While .Busy Or .readyState <> 4: DoEvents: Loop
   
    Set what = .document.getElementByName("onchage")
    what.Item(0).Value = myjobtype
   
    .document.getElementByName("B1").Click        '搜尋鍵
   
   
   
                With .document  '網頁的文件
                  '*** 這段程式碼可查看這網頁的元素內容
                    On Error Resume Next
                    For Each E In .all
                        i = i + 1
                        Cells(i, "a") = E.tagname   '控制項標記的名稱
                        Cells(i, "b") = E.ID        '控制項標記的ID (惟一的)
                        Cells(i, "c") = E.Name      '控制項標記的命名
                        Cells(i, "d") = E.Value     '控制項標記的值
                        Cells(i, "e") = E.innertext '控制項標記的文字
                        Cells(i, "f") = E.Type      '控制項標記的類型
                        Cells(i, "g") = E.href      '控制項標記的網址
                    Next
                  '****************************************
                End With
                '.QUIT
    End With

End Sub

附上檔案內容,請大大幫忙下!!

農產品價格.rar (30.55 KB)

TOP

太感謝GBKEE大大了!! 可以使用。
另外請問以下變數在哪裡有說明資料?
xTable(i).Rows.Length - 1
xTable(i).Rows(r).Cells.Length - 1
Cells(k + r, c + IIf(i = 0, 1 + 1 * c, 1)) = xTable(i).Rows(r).Cells(c).innerText

TOP

        靜思自在 : 有時當思無時苦,好天要積雨來糧。
返回列表 上一主題