首页 > 解决方案 > 如何使用 VBA 刷新查询表

问题描述

我正在使用查询表将 csv 文件调用到特定工作表。我希望每 30 秒刷新一次。我有以下代码可以在 csv 文件中调用,但我看不到让刷新工作。代码运行,将 csv 数据放入正确的工作表中,但似乎没有刷新 有人可以指出我的写入方向吗?这有点尴尬,因为我在 Python 和 MATLAB 中编写代码,但使用 VBA 我很难掌握它。谢谢你的帮助

Dim fileName As String
fileName = "C:\Users\aofarrell\Desktop\Book1.csv"

    With ThisWorkbook.Sheets("Sheet8").QueryTables.Add(Connection:= _
    "TEXT;" & fileName, Destination:=Range("$A$1"))
        '.Name = "CAPTURE"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0.5
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=True


    End With

End Sub

标签: excelvbacsv

解决方案


推荐阅读