将* .txt文件导入excel,从变量文本名称(VBA)

时间:2018-03-21 11:59:49

标签: excel-vba variables import vba excel

通过一些线程获得一些关于将* .txt文件导入Excel的建议,但无法使修改后的代码生效: (在此部分代码应用程序向用户询问lollot变量清除文件路径的文件路径之前。

Dim lollot As String

lollot = Replace(strFileToOpen, file path, "")

With ActiveSheet.QueryTables.Add(Connection:= _
    "TEXT;" & lollot, Destination:= _
    Range("A1"))
    .Name = lollot
    .FieldNames = True
    .RowNumbers = False
    .CommandType = 0
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .TextFilePromptOnRefresh = False
    .TextFilePlatform = 65001
    .TextFileStartRow = 1
    .TextFileParseType = xlDelimited
    .TextFileTextQualifier = xlTextQualifierDoubleQuote
    .TextFileConsecutiveDelimiter = False
    .TextFileTabDelimiter = True
    .TextFileSemicolonDelimiter = False
    .TextFileCommaDelimiter = False
    .TextFileSpaceDelimiter = False
    .TextFileColumnDataTypes = Array(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, _
    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 _
    , 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, _
    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 _
    )
    .TextFileTrailingMinusNumbers = True
    .Refresh BackgroundQuery:=False
End With

因此代码在运行时没有提供任何错误消息,它只是没有做任何事情。

0 个答案:

没有答案