嗨:我正在使用excel从这个网页中获取值:https://www2.agenciatributaria.gob.es/es13/h/iexmmmfi.html
如何获得excel VBA的代码以获得NIF、EJF、MOD和CEL的fiels?
我尝试使用getelementbyid("NIF")和"name“,但是没有结果。
谢谢!
Previos线程:Excel VBA: Get inner text of HTML table td
这是我使用的代码:
Sub AEAT()
Dim IE As Object
Application.ScreenUpdating = False
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "https://www2.agenciatributaria.gob.es/es13/h/iexmmmfi.html"
Application.Wait (Now + TimeValue("0:00:02"))
IE.Document.getElementById("NIF").Value = Range("A1").Value
Application.Wait (Now + TimeValue("0:00:01"))
IE.Document.getElementById("EJF").Value = "2016"
Application.Wait (Now + TimeValue("0:00:01"))
IE.Document.getElementById("MOD").Value = "347"
Application.Wait (Now + TimeValue("0:00:01"))
IE.Document.getElementById("CEL").Value = Range("a4").Value
Application.Wait (Now + TimeValue("0:00:01"))
IE.Document.getElementById("env_button").Click
End Sub发布于 2017-08-20 09:34:10
Okie,所以我在Windows中没有Excel,所以我使用VBScript测试了您的代码。所以解决办法应该有效。你有三个问题
溶液
在IE设置中将站点添加到受信任的站点。

手动打开IE并安装ActiveX控件
Sub AEAT()
Dim IE
Set IE = CreateObject("InternetExplorer.Application")
IE.visible = True
hwnd = ie.hwnd
IE.Navigate "https://www2.agenciatributaria.gob.es/es13/h/iexmmmfi.html"
msgbox ("wait")
Set oShell = CreateObject("Shell.Application")
For Each Wnd In oShell.Windows
If hwnd = Wnd.hwnd Then Set ie = Wnd
Next
IE.Document.getElementById("NIF").Value = "123"
End Sub
Call AEAT我已经将msgbox放到了插入“等待”的位置,但是您可以通过在excel中使用下面的命令来修复这个问题。
Do
DoEvents
Loop Until ie.ReadyState = READYSTATE_COMPLETEPS:参考以下网址
Internet Explorer VBA Automation Error: The object Invoked has disconnected from its clients
https://stackoverflow.com/questions/45768562
复制相似问题