返回列表 上一主題 發帖

[發問] 文字檔要如何反序匯入Excel 呢?

回復 1# mgame168
  1. Sub Ex()
  2. Dim MyString As String, i%
  3. Open "MYFILE" For Input As #1    ' 開啟輸入檔。
  4. i = 0
  5. Do While Not EOF(1)              ' 檢查是否已到檔尾。
  6.     Line Input #1, MyString      ' 將資料讀入變數中。
  7.     ActiveCell.Offset(i).Value = MyString     '往下寫入
  8.     'ActiveCell.Offset(0, i).Value = MyString '往右寫入
  9.     i = i + 1
  10. Loop
  11. Close #1
  12. End Sub
複製代碼

TOP

開啟的檔案不是特大時可試試
  1. Sub Ex()
  2.     Dim mystr$, Allstr$, Ar
  3.     Open "D:\Test\Test.txt" For Input As #1  
  4.     Do While Not EOF(1)
  5.         Line Input #1, mystr
  6.         Allstr = IIf(Allstr <> "", Allstr & "GBK", "") & mystr
  7.     Loop
  8.     Close #1
  9.     Ar = Split(Allstr, "GBK")
  10.     [A1].Resize(UBound(Ar) + 1, 1) = Application.Transpose(Ar)
  11. End Sub
複製代碼

TOP

本帖最後由 GBKEE 於 2011-5-20 11:36 編輯

回復 5# mgame168
是這樣嗎?      不要打謎題
  1. Sub Ex()
  2.     Dim mystr$, Allstr$, Ar
  3.     Open "D:\Test.txt" For Input As #1
  4.     Do While Not EOF(1)
  5.         Line Input #1, mystr
  6.         If Len(mystr) > 0 And mystr <> " " Then Allstr = IIf(Allstr <> "", Allstr & "***", "") & mystr
  7.     Loop
  8.     Close #1
  9.     Ar = Split(StrReverse(Allstr), "***")
  10.     [A1].Resize(1, UBound(Ar)) = Ar
  11. End Sub
複製代碼

TOP

        靜思自在 : 人生不一定球球是好球,但是有歷練的強打者,隨時都可以揮棒。
返回列表 上一主題