简体   繁体   English

Excel VBA QueryTables 保留超链接

[英]Excel VBA QueryTables Preserve Hyperlinks

I use QueryTables quite a lot in VBA to scrape data from webpages.我在 VBA 中大量使用QueryTables从网页中抓取数据。 I wondered if there was a way to preserve the hyperlinks that the webpage the query is pulling data from has.我想知道是否有办法保留查询从中提取数据的网页的超链接。

Here is an example Query:这是一个示例查询:

With ActiveSheet.QueryTables.Add(Connection:= _
 "URL;http://dom.com/table, Destination:=Range("$A$1"))
 .Name = "table"
 .FieldNames = True
 .RowNumbers = False
 .FillAdjacentFormulas = False
 .PreserveFormatting = True
 .RefreshOnFileOpen = False
 .BackgroundQuery = True
 .RefreshStyle = xlInsertDeleteCells
 .SavePassword = False
 .SaveData = True
 .AdjustColumnWidth = True
 .RefreshPeriod = 0
 .WebSelectionType = xlSpecifiedTables
 .WebFormatting = xlWebFormattingRTF
 .WebTables = """datatable"""
 .WebPreFormattedTextToColumns = True
 .WebConsecutiveDelimitersAsOne = True
 .WebSingleBlockTextImport = False
 .WebDisableDateRecognition = False
 .WebDisableRedirections = False
 .Refresh BackgroundQuery:=False
End With

The trick was changing .WebFormatting = xlWebFormattingRTF to .WebFormatting = xlWebFormattingAll诀窍是将.WebFormatting = xlWebFormattingRTF更改为.WebFormatting = xlWebFormattingAll

Additional Resources:其他资源:

https://docs.microsoft.com/en-us/office/vba/api/excel.querytable.webformatting https://docs.microsoft.com/en-us/office/vba/api/excel.xlwebformatting https://docs.microsoft.com/en-us/office/vba/api/excel.querytable.webformatting https://docs.microsoft.com/en-us/office/vba/api/excel.xlwebformatting

Name              Value Description
xlWebFormattingAll  1   All formatting is imported.
xlWebFormattingNone 3   No formatting is imported.
xlWebFormattingRTF  2   Rich Text Format - compatible formatting is imported.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM