Option Explicit
Private Sub UserForm_Initialize()
With Me
.lstText.Clear
.lblFilePath.Caption = Empty
End With
End Sub
Private Sub cmdRun_Click()
Const szFileName As String = "ReadMe.txt"
With Me
.lstText.Clear
.lblFilePath.Caption = Empty
End With
Dim szThisPath As String
szThisPath = ThisWorkbook.Path
Dim szPathSep As String
szPathSep = Application.PathSeparator
Dim szValidPath As String
szValidPath = szThisPath & szPathSep & szFileName
Me.lblFilePath.Caption = "Reading file from: " & szValidPath
On Error GoTo ErrHandler
Dim lFile As Long
Dim szLine As String
lFile = FreeFile()
Open szValidPath For Input As lFile
While Not EOF(lFile)
Line Input #lFile, szLine
Me.lstText.AddItem szLine
Wend
Close lFile
Exit Sub
ErrHandler:
Me.lblFilePath.Caption = Empty
MsgBox Err.Description
End Sub
Private Sub lstText_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim i As Long
For i = 0 To Me.lstText.ListCount - 1
Me.lstText.Selected(i) = False
Next i
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Sub ShowMyForm()
frmGetTxt.Show
End Sub
|