查询当前网站上的Web表格

我遇到了一些问题。 通常情况下,当我拉一个表,我在Excel中使用“数据从networking”工具,但是我现在有相当多的地方需要拉数据,首先要求我input用户名和密码。 我想出了一些代码(虽然可能不是最优雅的),但意识到,一旦我到达我想要的页面,我不知道如何提取表。 这是我迄今为止。

Sub Login() Sheets("IOL").Select Set ie = CreateObject("InternetExplorer.application") ie.Visible = True ie.Navigate ("https://internalsite.company.com/secure/login" & ActiveCell) Do If ie.ReadyState = 4 Then ie.Visible = True Exit Do Else DoEvents End If Loop ie.Document.forms(0).all("badgeBarcodeId").Value = "00000" ie.Document.forms(0).submit 'used because it redirects to a new page after submitting and I couldn't figure out how to make it wait for the new page to load before proceeding. Application.Wait (Now + TimeValue("0:00:02")) ie.Document.forms(0).all("password").Value = "00000" ie.Document.forms(0).submit End Sub 

login完成后,我想要访问http://internalsite.company.com/csv并直接将csv导入到工作表中。 任何时候我build立一个新的连接,这使我再次login,所以我认为必须有一种方法来提取文件,而无需添加新的连接。 对于更复杂的VBA,我很新,所以请耐心等待。

我能够得到这个代码来完成这个工作,但是更好的办法是直接获取CSV而不是表格。 有时表不喜欢加载。

  Sub Login() Dim clip As DataObject Dim ieTable As Object Set ie = CreateObject("InternetExplorer.application") ie.Visible = True ie.Navigate ("https://internalsite1.company.com/secure/login" & ActiveCell) Do If ie.ReadyState = 4 Then ie.Visible = True Exit Do Else DoEvents End If Loop ie.Document.forms(0).all("badgeBarcodeId").Value = "00000" ie.Document.forms(0).submit Do While ie.Busy: DoEvents: Loop Do Until ie.ReadyState = 4: DoEvents: Loop ie.Document.forms(0).all("password").Value = "000000" ie.Document.forms(0).submit Do While ie.Busy: DoEvents: Loop Do Until ie.ReadyState = 4: DoEvents: Loop ie.Navigate "http://internalsite2.company.com/site/Inbound?filter=1To3Days" Do While ie.Busy: DoEvents: Loop Do Until ie.ReadyState = 4: DoEvents: Loop Set ieTable = ie.Document.all.Item("DataTables_Table_0") If Not ieTable Is Nothing Then Set clip = New DataObject clip.SetText "" & ieTable.outerHTML & "" clip.PutInClipboard Workbooks("Production Meeting Dashboard.xlsm").Activate Sheets("IOL").Select Range("A1").Select ActiveSheet.PasteSpecial Format:="Unicode Text", link:=False, _ DisplayAsIcon:=False, NoHTMLFormatting:=True End If End Sub