从文本文件中获取所有文本并在UserForm文本框中显示

我正在使用下面的代码从文本文件中读取文本并将所有文本放在我的用户窗体文本框中。 我遇到的问题是当文本显示在文本框中显示无格式,即文本除以换行符如:

The cat went east The dog went south 

全部在一行上阅读,并且在文本中具有这些奇怪的“P”符号,如:

 'P'The cat went east 'P'The dog went south'P' 

所以我的一个问题是如何恢复文本的格式显示像这样?

  The cat went east The dog went south 

最后我的文本将被切断文本框的视图,因为文本框只是如此之大,但我的文本可能是多行,如:

 The cat went east The dog went south The cat went east The dog went south The cat went east The dog went south The cat went east The dog went south 

那么我怎样才能把滚动上/下function添加到文本框?

码:

 Private Sub UserForm_Activate() m1 = Month(Range("C" & ActiveCell.Row).Value) M = MonthName(m1, True) Y = Year(Range("C" & ActiveCell.Row).Value) Dim Total As String Dim FilePath As String Dim strLine As String FilePath = "\\MI-FILESERVE1\Shared Folders\Shared_Business_Dev\Tenders\" & Range("G" & ActiveCell.Row).Value & "\" & Range("E" & ActiveCell.Row).Value & "\" & Range("F" & ActiveCell.Row).Value & " - " & M & " - " & Y & "\log.txt" Open FilePath For Input As #1 While EOF(1) = False 'read the next line of data in the text file Line Input #1, strLine Total = Total & vbNewLine & strLine 'increment the row counter i2 = i2 + 1 Wend Close #1 TextBox1 = Total End Sub 

如果TextBox不是MultiLine模式,则换行符将显示为¶。

您可以使用MultiLine属性以MultiLine模式设置TextBox

TextBox1.MultiLine = True

要获取TextBox的所有可能属性和方法的列表,请尝试使用关键字TextBox的帮助。 或者只需键入TextBox1. 然后看看列出了哪些可能的属性和方法。