我想通过VBA将文本文件导入到Excel中,但经过大量搜索和测试后,我似乎无法弄清楚如何格式化它,因为我想要。从文本文件导入特定文本到excel表
这里的文本文件的一部分:
^USER ADDRESS
User's name
Street address
Postal code and town
^USER ORDER NUMBER
Order number
^AND SO ON.....
导入时,我希望它格式化这样的:
^USER ADDRESS | User's name | Street address | Postal code and town
^USER ORDER NUMBER | Order number
^AND SO ON ....
这是我的脚本这么远。它复制包含^ USER的行并将其粘贴 - 但我需要它复制每个^下面的行,直到下一个^。
Private Sub DatafrmTxt()
Dim myFile As String, text As String
Dim F As Long
Dim x As Integer
myFile = "C:\test.txt"
F = FreeFile
x = 1
Open myFile For Input As F
Do Until EOF(F)
Line Input #F, text
If InStr(text, "^USER ") > 0 Then
Range("A" & x).Value = text
x = x + 1
End If
Loop
Close F
End Sub