使用未定义的vba用户定义类型从受密码保护的网站中删除数据
我想从受密码保护的网站()导入数据,我有用户名和密码 我在这个网站上尝试过迪克编写的VBA代码:但它不起作用,每次我调整它时都会卡住 它卡在这里:使用未定义的vba用户定义类型从受密码保护的网站中删除数据,vba,excel,web-scraping,Vba,Excel,Web Scraping,我想从受密码保护的网站()导入数据,我有用户名和密码 我在这个网站上尝试过迪克编写的VBA代码:但它不起作用,每次我调整它时都会卡住 它卡在这里: Sub GetTable() Dim ieApp As InternetExplorer Dim ieDoc As Object Dim ieTable As Object Dim clip As DataObject 'create a new instance of ie Set ieApp = New InternetExplorer '
Sub GetTable()
Dim ieApp As InternetExplorer
Dim ieDoc As Object
Dim ieTable As Object
Dim clip As DataObject
'create a new instance of ie
Set ieApp = New InternetExplorer
'you don’t need this, but it’s good for debugging
ieApp.Visible = True
'assume we’re not logged in and just go directly to the login page
ieApp.Navigate "https://www.vesseltracker.com/fr/Home.html"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
Set ieDoc = ieApp.Document
'fill in the login form – View Source from your browser to get the control names
With ieDoc.forms(0)
.UserName.Value = "username"
.Password.Value = "password"
.submit
End With
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
'now that we’re in, go to the page we want
ieApp.Navigate "https://www.vesseltracker.com/fr/Port/tangermed/Dashboard.html"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
'get the table based on the table’s id
Set ieDoc = ieApp.Document
Set ieTable = ieDoc.all.Item
'copy the tables html to the clipboard and paste to teh sheet
If Not ieTable Is Nothing Then
Set clip = New DataObject
clip.SetText "" & ieTable.outerHTML & ""
clip.PutInClipboard
Sheet1.Select
Sheet1.Range("A1").Select
Sheet1.PasteSpecial "Unicode Text"
End If
'close 'er up
ieApp.Quit
Set ieApp = Nothing
End Sub
我真的很感谢你的帮助。谢谢。您可以像这样添加所需的参考: 您需要包括MSForms库
C:\Windows\system32\FM20.DLL
最简单的方法是向项目中添加一个userform。
()
或者,您可以通过以下方式添加库:
工具>引用>浏览>
C:\Windows\system32\FM20.DLL
由于引用中不存在MSForms,因此类型DataObject
未定义
您可以使用后期绑定来设置剪贴板中的某些文本:
With VBA.CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
.SetText "1234"
.PutInClipboard
End With
这个词是“刮”,而不是“导入”。)好的,我来换。(别忘了✓接受一个有助于你解决问题的答案-你获得+2声誉,被接受答案的作者获得+15声誉!一旦你达到15个代表,你也可以▲把你认为有用的回答都写出来。