返回列表 上一主題 發帖

請問如何將選取的txt檔內容匯入指定儲存格呢?

回復 2# Mindyj
  1. Sub ex()
  2. fs = ThisWorkbook.Path & "\import.txt"
  3. Open fs For Input As #1
  4. i = 6
  5. Do While Not EOF(1)    ' 執行迴圈直到檔尾為止。
  6.     Line Input #1, TextLine
  7.     Cells(i, 1) = TextLine
  8.     i = i + 1
  9. Loop
  10. Close #1
  11. End Sub
複製代碼
學海無涯_不恥下問

TOP

回復 4# Mindyj
  1. Sub import()
  2. Dim A As Range
  3. fs = Application.GetOpenFilename("Text Files (*.txt), *.txt")
  4. Set A = Application.InputBox("選擇文字檔要放置的位置", , "$A$1", , , , , 8)
  5. Open fs For Input As #1
  6. Do While Not EOF(1)    ' 執行迴圈直到檔尾為止。
  7.     Line Input #1, TextLine
  8.     A.Offset(i, 0) = TextLine
  9.     i = i + 1
  10. Loop
  11. Close #1
  12. End Sub
複製代碼
學海無涯_不恥下問

TOP

        靜思自在 : 靜坐常恩己過、閒談莫論人非。
返回列表 上一主題