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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top