路径是变量的问题,新手求教啊
我要把txt中数据导入到excel,代码是在excel中录制的宏指令。txt文件的路径是变量A(),其中A(i)是txt文件的完整路径,类似C:\Users\THINK\Desktop\数据.txt这种。代码中With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Users\THINK\Desktop\数据.txt", Destination:=Range("Sheet1!$A$1"))要怎么改才可以?
程序代码:
Private Sub Macro(A() As String) Dim n As Integer n = Val(Text1.Text) Dim i As Integer For i = 1 To n Debug.Print A(i) Sheets("Sheet" & i).Select With ActiveSheet.QueryTables.Add(Connection:= _ "TEXT;C:\Users\THINK\Desktop\数据.txt", Destination:=Range("$A$1")) .Name = "1" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = 936 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = True .TextFileTabDelimiter = True .TextFileSemicolonDelimiter = False .TextFileCommaDelimiter = False .TextFileSpaceDelimiter = True .TextFileColumnDataTypes = Array(1, 1, 1, 1) .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False End With Next End Sub