[VBA] Call JavaScript method in VBA
這是一個來自網路捧油的問題
http://www.dotblogs.com.tw/yc421206/archive/2009/11/02/11380.aspx#23915
其中有一項問題是下拉式選單的值(DropDownList1)已經變了,但是查詢頁面沒有變;我猜想這應該是沒有postback,研究了一下,果真如此。
來看一下左邊框架的網頁原始碼,我們可以看到下一頁事件是 onclick="f_goDropDownList('next')" ,所以只要針對那個事件的方法就能查到我們要的頁面。
為了測試我改了一下原作的程式碼並加上
If myIE Is Nothing Then
Exit Sub
End If
With myIE
loadOK
With myIE.Document
'取得左頁框
Set theFrame_L = .getElementsByTagName("frame")(0)
theFrame_L.contentWindow.Document.getElementsByName("DropDownList1")(0).Value = Range("A1").Value - 1
Call theFrame_L.contentWindow.Document.parentWindow.execScript("f_goDropDownList('next')", "javascript")
loadOK
End With
End With
End Sub
主要是這一行能讓下拉式選單的值變更後
執行畫面如下
範例下載
若有謬誤,煩請告知,新手發帖請多包涵

Microsoft MVP Award 2010~2017 C# 第四季
Microsoft MVP Award 2018~2022 .NET
