返回列表 上一主題 發帖

如何每次開啟選擇匯入文字檔之路徑

回復 1# sping
試試看
  1. Sub Macro1()
  2. '
  3. ' Macro1 Macro
  4. ' 匯入檔案
  5. '

  6. '
  7.    txtFile = Application.GetOpenFilename("文字檔, *.txt")
  8.    txtFile = "TEXT;" & txtFile
  9.     With ActiveSheet.QueryTables.Add(Connection:=txtFile, Destination:=Range("$A$2"))
  10.         .FieldNames = True
  11.         .RowNumbers = False
  12.         .FillAdjacentFormulas = False
  13.         .PreserveFormatting = True
  14.         .RefreshOnFileOpen = False
  15.         .RefreshStyle = xlInsertDeleteCells
  16.         .SavePassword = False
  17.         .SaveData = True
  18.         .AdjustColumnWidth = True
  19.         .RefreshPeriod = 0
  20.         .TextFilePromptOnRefresh = False
  21.         .TextFilePlatform = 950
  22.         .TextFileStartRow = 1
  23.         .TextFileParseType = xlFixedWidth
  24.         .TextFileTextQualifier = xlTextQualifierDoubleQuote
  25.         .TextFileConsecutiveDelimiter = False
  26.         .TextFileTabDelimiter = True
  27.         .TextFileSemicolonDelimiter = False
  28.         .TextFileCommaDelimiter = False
  29.         .TextFileSpaceDelimiter = False
  30.         .TextFileColumnDataTypes = Array(9, 1, 9, 9)
  31.         .TextFileFixedColumnWidths = Array(38, 32, 28)
  32.         .TextFileTrailingMinusNumbers = True
  33.         .Refresh BackgroundQuery:=False
  34.     End With
  35.     ActiveWindow.SmallScroll Down:=-27
  36. End Sub
複製代碼

TOP

        靜思自在 : 【停滯不前,終無所得】人都迷於尋找奇蹟,因而停滯不前;縱使時間再多、路再長,也了無用處,終無所得。
返回列表 上一主題