删除txt文件中的最后一个单词

时间:2017-02-23 12:57:49

标签: excel vba excel-vba

早上好

我有一个名为" txt"的txt文件。有4条线。 我的问题是我想删除最后3行中的最后两个单词。

这是我在txt中的文字:

"vol"
"vui one high"  one high
"vui one front "    two high
"vuil high front "      three   high

删除的字是引号后的2。

我有一个代码,但此时它只允许替换一个单词 这是我的代码的开头:

Sub CommandButton1_Click()

    Dim sBuf As String
    Dim sTemp As String
    Dim iFileNum As Integer
    Dim sFileName As String

    ' Edit as needed
    sFileName = "C:\Users\bquinty\Desktop\txt.txt"

    iFileNum = FreeFile
    Open sFileName For Input As iFileNum

    Do Until EOF(iFileNum)
    Line Input #iFileNum, sBuf
    sTemp = sTemp & sBuf & vbCrLf
    Loop
    Close iFileNum

    sTemp = Replace(sTemp, "word to remplace", "word wanted")

    'Save txt file as (if possible)

    iFileNum = FreeFile
    sFileName = "C:\Users\bquinty\Desktop\txt.txt"
    Open sFileName For Output As iFileNum

    Print #iFileNum, sTemp

    Close iFileNum


    End Sub

感谢您提供的所有帮助/建议。

0 个答案:

没有答案