Option Explicit Sub 股市行情() Dim wsg As Worksheet Dim QT As QueryTable Dim Fina1row As Long Dim i As Integer Dim cntr As String Dim rg As Range Dim crg As Range
Set wsg = Worksheets("股市行情") Fina1row = wsg.Range("a65536").End(xlUp).Row For i = 6 To Fina1row Select Case i Case 6 cntr = "URL;http://stock.business.sohu.com/p/pl.php?code=" & wsg.Cells(i, 1).Value Case Else cntr = cntr & "," & Format(wsg.Cells(i, 1).Value, "000000") End Select Next i For Each QT In wsg.QueryTables QT.Delete Next QT Set rg = wsg.Range(Cells(5, 1), Cells(Fina1row, 11)) rg.Clear Set QT = wsg.QueryTables.Add(Connection:=cntr, Destination:=wsg.Range("a5")) With QT .Name = "我的股市行情" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = False .RefreshPeriod = 0 .WebSelectionType = xlSpecifiedTables .WebFormatting = xlWebFormattingRTF .WebTables = "13" .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False End With QT.Refresh BackgroundQuery:=False Set crg = QT.ResultRange.Columns(1) crg.NumberFormatLocal = "000000" QT.ResultRange.Columns(QT.ResultRange.Columns.Count).Clear Range("a5").CurrentRegion.Borders.LineStyle = xlContinuous End Sub Public Sub 刷新在每隔20秒钟后运行() Application.OnTime Now + TimeValue("00:00:20"), "刷新" End Sub Public Sub 刷新() Application.ScreenUpdating = False With Sheet1.QueryTables(1) If .PreserveFormatting = False Then .PreserveFormatting = True .Refresh End With Application.ScreenUpdating = True Call 刷新在每隔20秒钟后运行 End Sub 我按照这个代码完全自己做了一遍,为什么提示Set QT = wsg.QueryTables.Add(Connection:=cntr, Destination:=wsg.Range("a5")) 这一句错误 |