如何在刷新后保持Web导入数据的新结构?

我正在创build一个Excel数据库。 我想从公司网站上input公司所有员工的姓名,电子邮件和工作职位。 我selectData-> From Web并select整个页面,因为这是唯一的可能性。

该页面显示没有数据的表格; 只是一长串名单,电子邮件和旁边的工作职位的雇员的照片

我将数据导入到我的Excel电子表格中:格式非常糟糕。 因此,我开始剪切和粘贴创build一个“姓名”,一个“电子邮件”和类似的“职位”列。 所有其他信息被手动取消。

我想刷新保持这种新格式的数据。 不幸的是,每次使用“全部刷新”button刷新导入的数据时,它们都会返回到原始格式。

如何在刷新后保持我的Web导入数据的新格式?

我感谢大家的支持!

Kr,A

我已经把一个例子从你指定的那个页面中提取名字和标题,并把它们放到表单1中。

该代码将只能提供底层HTML的布局保持不变。 它不支持更新现有列表(在再次阅读列表之前,表1上的任何内容都被删除)

要使用这个代码,你必须把它放在一个新的代码模块(不是工作表或者工作簿部分)中,你可以从代码编辑器或者在主窗口的macros菜单中运行它。

' Note: This code requires the following references to be loaded. ' Microsoft HTML Object Library (mshtml.tlb) ' Microsoft Internet Controls (ieframe.dll) ' To add a reference ' In the VBA Code Editor, in the Tools Menu click the References item ' Scroll through the list and ensure that the references are selected ' Press OK and your done. Sub Scrape() Dim Browser As InternetExplorer Dim Document As HTMLDocument Dim Element As IHTMLElement Dim Elements As IHTMLElementCollection Dim empName As String Dim empTitle As String Dim Sheet As Worksheet Set Sheet = ThisWorkbook.ActiveSheet Sheet.UsedRange.ClearContents ' Nuke the old list Set Browser = New InternetExplorer Browser.navigate "http://www.hsbc.com/about-hsbc/leadership" Do While Browser.Busy And Not Browser.readyState = READYSTATE_COMPLETE DoEvents Loop Set Document = Browser.Document Set Elements = Document.getElementsByClassName("profile-col1") For Each Element In Elements empName = Trim(Element.Children(1).Children(0).innerText) empTitle = Trim(Element.Children(1).Children(1).innerText) Sheet.Range("A1:B1").Insert xlShiftDown Sheet.Cells(1, 1).Value = empName Sheet.Cells(1, 2).Value = empTitle 'Debug.Print "[ name] " & empName 'Debug.Print "[ title] " & empTitle Next Element Set Browser = Nothing Set Elements = Nothing End Sub