VBA设置下拉值

我有一个macros,我写在Excel中,我已经导航到一个网页使用“ActiveWorkbook.FollowHyperlink”,它的工作就像我需要它!

不过,我现在需要更新该网页上的下拉菜单。

我有一个下拉ID和每个select显然有一个值。 我想使用我在Excel工作表中的值来设置选定的选项。

我很挣扎,因为我不知道如何访问页面上的元素,一旦使用.FollowHyperlink打开。

之后.FollowHyperlink是网页然后激活,有没有像ActiveWebPage.getElementById?

感谢任何帮助。

麦克风

你想要做的是使用COM自动化调用Internet Explorer的实例,并导航到有问题的页面,这将给你的文档模型,从那里你可以做任何事情,请参阅IE(Internet Explorer)自动化使用Excel VBA

样本VBA如下

Private Sub IE_Autiomation() Dim i As Long Dim IE As Object Dim objElement As Object Dim objCollection As Object ' Create InternetExplorer Object Set IE = CreateObject("InternetExplorer.Application") IE.Visible = False IE.Navigate "http://www.excely.com/" ' Statusbar Application.StatusBar = "www.excely.com is loading. Please wait..." ' Wait while IE loading... Do While IE.Busy Application.Wait DateAdd("s", 1, Now) Loop ' Find 2 input tags: ' 1. Text field ' <input type="text" class="textfield" name="s" size="24" value="" /> ' ' 2. Button ' <input type="submit" class="button" value="" /> Application.StatusBar = "Search form submission. Please wait..." Set objCollection = IE.document.getElementsByTagName("input") i = 0 While i < objCollection.Length If objCollection(i).Name = "s" Then ' Set text for search objCollection(i).Value = "excel vba" Else If objCollection(i).Type = "submit" And _ objCollection(i).Name = "" Then ' "Search" button is found Set objElement = objCollection(i) End If End If i = i + 1 Wend objElement.Click ' click button to search ' Wait while IE re-loading... Do While IE.Busy Application.Wait DateAdd("s", 1, Now) Loop ' Show IE IE.Visible = True ' Clean up Set IE = Nothing Set objElement = Nothing Set objCollection = Nothing Application.StatusBar = "" End Sub