Excel 2007 VBA宏逐行读取文本文件如何停止逗号(,)的分隔

时间:2021-06-02 02:23:30

I have a simple Excel 2007 Macro that is reading a text file line by line and displaying the output.

我有一个简单的Excel 2007宏,它逐行读取文本文件并显示输出。

This macro is breaking on commas. I want it to simply read the entire line breaking on a carrage return.

这个宏在逗号上打破了。我希望它只是简单地读取整个线路在一个carrage返回。

What am I doing wrong?

我究竟做错了什么?

Sub Directory()
  Dim strFileName As String
  Dim strDirectory As String
  Dim intFileKey As Integer
  Dim strLine As String

  strDirectory = "C:\Documents and Settings\e1009028\My Documents\embosstest"

  ChDir (strDirectory)

  strFileName = Dir("*.txt")

  Do While Len(strFileName) > 0
    intFileKey = FreeFile
    Open strFileName For Input As intFileKey
    Do While Not EOF(intFileKey)
        Input #intFileKey, strLine
        MsgBox Mid(strLine, 1, 10)
    Loop
    strFileName = Dir
  Loop

End Sub

Here is a sample text file:

这是一个示例文本文件:

1 blahblahblabh
2 blah,blahblah

1 个解决方案

#1


5  

For a quick fix, try using Line input instead of input.

要快速解决问题,请尝试使用Line输入而不是输入。

For a more modern solution, have a look at FileSystemObject, especially OpenTextFile.

有关更现代的解决方案,请查看FileSystemObject,尤其是OpenTextFile。

#1


5  

For a quick fix, try using Line input instead of input.

要快速解决问题,请尝试使用Line输入而不是输入。

For a more modern solution, have a look at FileSystemObject, especially OpenTextFile.

有关更现代的解决方案,请查看FileSystemObject,尤其是OpenTextFile。