Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Opening textfile in textbox + moving to top

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Opening textfile in textbox + moving to top

Please refer the below link
http://support.microsoft.com/kb/209231

You can also use the Line input statement to retrieve a line at a time
--
If this post helps click Yes
---------------
Jacob Skaria


"Gustaf" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Opening textfile in textbox + moving to top

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

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

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Please refer the below link
http://support.microsoft.com/kb/209231

You can also use the Line input statement to retrieve a line at a time
--
If this post helps click Yes
---------------
Jacob Skaria


"Gustaf" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Opening textfile in textbox + moving to top

Jacob Skaria wrote:

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


Nice and tidy. Thank you very much!

If this post helps click Yes


Click yes?

Gustaf
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
TextBox validation before moving to next LuisE Excel Programming 3 August 25th 07 11:48 PM
Moving Data on opening Excel Rainbow-Lentil New Users to Excel 3 July 12th 07 04:43 PM
Textbox keeps moving [email protected] Excel Programming 1 June 15th 05 12:34 AM
Opening and saving textfile into XLS MicMast Excel Programming 1 August 4th 03 01:33 PM
Code for moving textbox Phil Perry Excel Programming 2 July 9th 03 03:49 PM


All times are GMT +1. The time now is 09:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"