首页 > 解决方案 > 带有 HTML 表的 VBA QueryTables 连接错误

问题描述

我正在尝试从 IMF tsv 文件中提取汇率,并且我的代码一直在尝试联系服务器以获取信息。过去它确实有效。如果我通过按 esc 终止代码,它确实提供了新数据。

我究竟做错了什么?有没有人建议防止这种情况发生?

 Sub IMF()
    Dim ConnString As String
    Dim wsIMF As Worksheet
    Set wsIMF = Sheets("IMF Exchange rates")
    
    wsIMF.Cells.ClearContents
    ConnString = "TEXT;http://www.imf.org/external/np/fin/data/rms_five.aspx?tsvflag=Y"
        With wsIMF.QueryTables.Add(Connection:=ConnString, Destination:=wsIMF.Range("A1"))
            .Name = _
            " "
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = False
            .RefreshPeriod = 0
            .TextFilePromptOnRefresh = False
            .TextFilePlatform = 775
            .TextFileStartRow = 1
            .TextFileParseType = xlDelimited
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = False
            .TextFileTabDelimiter = True
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = True
            .TextFileSpaceDelimiter = False
            .TextFileColumnDataTypes = Array(1)
            .TextFileDecimalSeparator = ","
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
        End With
    
    End Sub

标签: htmlvbaconnection

解决方案


推荐阅读