我有以下两段代码用于从Web服务中提取一个大表,一个用于URL连接:
With ActiveSheet.QueryTables.Add(Connection:="URL;" & URL, Destination:=Cells(1,1))
.PostText = ""
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = False
.WebSingleBlockTextImport = True
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
.WorkbookConnection.Delete
End With
一个用于TEXT连接:
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & URL, Destination:=Cells(1,1))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
.WorkbookConnection.Delete
End With
因为我有时需要向Web服务发送参数(通过PostText或长URL),因此URL连接更适合我的目的。但是,对于来自同一Web服务的相同数据集(在这种情况下不是参数),URL连接的刷新始终需要21秒,TEXT连接只需12秒。
为什么TEXT连接速度快得多?关于URL连接的相对缓慢,我能做些什么吗?