Opening textfile in textbox + moving to top

G

Gustaf

Found this code for opening a textfile in a textbox on a custom VBA form:

Private Sub UserForm_Initialize()

Dim hFile As Long
Dim sFilename As String

sFilename = conLinkHelpdesk

hFile = FreeFile
Open sFilename For Input As #hFile
txtText.Text = Input$(LOF(hFile), hFile)
Close #hFile

End Sub

Works fine, but when the form opens, the cursor is at the bottom, which causes the end of the textfile to show, rather than the beginning. Is there a way to correct this?

Gustaf
 
J

Jacob Skaria

Oops...You can use this code after closing the file

UserForm1.TextBox1.SetFocus
UserForm1.TextBox1.SelStart = 0

If this post helps click Yes
 
Top