【发布时间】:2019-06-18 18:05:15
【问题描述】:
我正在尝试编写允许我导入外部文本文件并按列格式化的代码。
我尝试了几种不同的方法,我认为分隔是我想做的最好的方法。
Sub Import_TxtFile()
Dim TXT As Range
Open "C:\Users\hpeshek\Desktop\Excel Testing\Test 3.txt" For Input As #1
'Run the procedure while it is not at the end of the file
Do While Not EOF(1) 'Loop until End of File
Line Input #1, TXT 'Read line into variable
'I think if i can get the following to work then the import will be successful
TXT.TextToColumns _
Destination:=Range("A1:"), _
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, _
Tab:=True, _
Semicolon:=False, _
Comma:=False, _
Space:=False, _
Other:=False, _
OtherChar:=False
Loop
Close #1 'Close file
End Sub
我认为我的问题是我无法将 TXT 格式化为 TextToColumns 函数的范围。有谁知道它应该被指定为什么?
【问题讨论】: