我有以下代碼,用於將文本從文本文件粘貼到我的工作表中。問題是它將所有內容都轉移到一行上!將文本文本從文本文件粘貼到工作表中,逐行寫入
例如,如果文本文件中讀取:
Opened by Joe Bloggs 24 Feb 2017 11:08:12
Closed by Joe Bloggs 24 Feb 2017 11:23:12
這都將粘貼到範圍(「A1」)爲:
Opened by Joe Bloggs 24 Feb 2017 11:08:12 Closed by Joe Bloggs 24 Feb 2017 11:23:12.
我寧願它是由線貼線下列A,使得:
Range("A1").Value = Opened by Joe Bloggs 24 Feb 2017 11:08:12
Range("A2").Value = Closed by Joe Bloggs 24 Feb 2017 11:23:12
我的代碼
Private Sub CommandButton1_Click()
Dim myFile As String, text As String, textline As String, Delimiter As String
myFile = "J:\...\Group Jobslist V1.2. Log.Log"
Open myFile For Input As #1
Do Until EOF(1)
Line Input #1, textline
text = text & textline
Loop
Close #1
Range("A1").Value = text
End Sub
'文檔'設施有一些很好的例子來幫助你做到這一點。查看包含遞增變量的Do While循環 - 這就是您作爲第一步後的內容(http://stackoverflow.com/documentation/vba/1873/flow-control-structures#t=201702261159580372731)。 – Ambie