Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Adding text file to a user form?

I have made many user forms in the past. And I know you can have an
image show up in a user form. I am wondering if there is any way in
which I can show to the user the contents of a text file (.txt) while
they are making a choice in the user form (basically the text files
could be one of two types and I want the user to be able to see it and
then tell my macro which one it is). The text file will change each
time, because in the previous dialog box I have them find the text file
on their computer. Thanks in advance.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding text file to a user form?

You could read in the text file and put the text in a textbox.

--
Regards,
Tom Ogilvy

"Chip" wrote in message
ps.com...
I have made many user forms in the past. And I know you can have an
image show up in a user form. I am wondering if there is any way in
which I can show to the user the contents of a text file (.txt) while
they are making a choice in the user form (basically the text files
could be one of two types and I want the user to be able to see it and
then tell my macro which one it is). The text file will change each
time, because in the previous dialog box I have them find the text file
on their computer. Thanks in advance.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Adding text file to a user form?

I'm not sure what you mean? How would I go about doing that? Any code
to get me started would be great.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding text file to a user form?

Use Low Level fileio

Private Sub CommandButton1_Click()
strFile = "C:\xltext\myfile.txt"
hFile = FreeFile

Open strFile For Input As hFile

Do While Not EOF(hFile)
Line Input #hFile, strLine
sStr = sStr & strLine & Chr(10)
Loop
Close #hFile
UserForm1.TextBox1.Text = sStr
End Sub


RBSmissert posted this like which has some added information on low level
file io

http://www.applecore99.com/gen/gen029.asp


Of course, if your text file is large, you may only want to read in a couple
of lines


Private Sub CommandButton1_Click()
Dim strFile as String, hFile as long
Dim strLine as String, icnt as long
strFile = "C:\xltext\myfile.txt"
hFile = FreeFile

Open strFile For Input As hFile
icnt = 0
Do While icnt < 5
Line Input #hFile, strLine
sStr = sStr & strLine & Chr(10)
icnt = icnt + 1
Loop
Close #hFile
UserForm1.TextBox1.Text = sStr
End Sub

--
Regards,
Tom Ogilvy


"Chip" wrote in message
oups.com...
I'm not sure what you mean? How would I go about doing that? Any code
to get me started would be great.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding text file to a user form?

Make sure the textbox property for multiline is set to true.

--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
Use Low Level fileio

Private Sub CommandButton1_Click()
strFile = "C:\xltext\myfile.txt"
hFile = FreeFile

Open strFile For Input As hFile

Do While Not EOF(hFile)
Line Input #hFile, strLine
sStr = sStr & strLine & Chr(10)
Loop
Close #hFile
UserForm1.TextBox1.Text = sStr
End Sub


RBSmissert posted this like which has some added information on low level
file io

http://www.applecore99.com/gen/gen029.asp


Of course, if your text file is large, you may only want to read in a

couple
of lines


Private Sub CommandButton1_Click()
Dim strFile as String, hFile as long
Dim strLine as String, icnt as long
strFile = "C:\xltext\myfile.txt"
hFile = FreeFile

Open strFile For Input As hFile
icnt = 0
Do While icnt < 5
Line Input #hFile, strLine
sStr = sStr & strLine & Chr(10)
icnt = icnt + 1
Loop
Close #hFile
UserForm1.TextBox1.Text = sStr
End Sub

--
Regards,
Tom Ogilvy


"Chip" wrote in message
oups.com...
I'm not sure what you mean? How would I go about doing that? Any code
to get me started would be great.







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Adding text file to a user form?

Got it. Thanks...That's pretty cool.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Adding text file to a user form?

By the way, Tom you are the man

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Adding text file to a user form?


All these 2 methods are reading the text file line by line. But I have
very large text file (over 1000KB) needed to be put on the text box. I
a bit waste time and maybe error .

Is there any methods that I can put this large text file on the tex
box, other than the reading text method?

--
JaiJa
-----------------------------------------------------------------------
JaiJai's Profile: http://www.excelforum.com/member.php...fo&userid=1948
View this thread: http://www.excelforum.com/showthread.php?threadid=34071

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding text file to a user form?

Have you tried them?

That type of code reads in a file pretty fast.

there are ways to modify that to read in a file to a variable in one go.

--
Regards,
Tom Ogilvy

"JaiJai" wrote in
message ...

All these 2 methods are reading the text file line by line. But I have a
very large text file (over 1000KB) needed to be put on the text box. It
a bit waste time and maybe error .

Is there any methods that I can put this large text file on the text
box, other than the reading text method??


--
JaiJai
------------------------------------------------------------------------
JaiJai's Profile:

http://www.excelforum.com/member.php...o&userid=19484
View this thread: http://www.excelforum.com/showthread...hreadid=340711



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Adding text file to a user form?

JaiJai,
Just put the whole file into a RichTextBox ?

NickHK

"JaiJai" wrote in
message ...

All these 2 methods are reading the text file line by line. But I have a
very large text file (over 1000KB) needed to be put on the text box. It
a bit waste time and maybe error .

Is there any methods that I can put this large text file on the text
box, other than the reading text method??


--
JaiJai
------------------------------------------------------------------------
JaiJai's Profile:

http://www.excelforum.com/member.php...o&userid=19484
View this thread: http://www.excelforum.com/showthread...hreadid=340711





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Adding text file to a user form?


Yes, I have tried the all and it really time consuming to read and write
line by line.
The attached file is the text file (large file size) that I want to put
on the textbox.

Are there any other good methods ?


+-------------------------------------------------------------------+
|Filename: CSV-htaa.zip |
|Download: http://www.excelforum.com/attachment.php?postid=3653 |
+-------------------------------------------------------------------+

--
JaiJai
------------------------------------------------------------------------
JaiJai's Profile: http://www.excelforum.com/member.php...o&userid=19484
View this thread: http://www.excelforum.com/showthread...hreadid=340711

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding text file to a user form?

Private Sub CommandButton1_Click()
Dim sStr As String
strFile = "C:\Data6\CSV-htaa.txt"
Hfile = FreeFile

Open strFile For Input As Hfile
i = LOF(Hfile)
sStr = Input(i, #Hfile)
Close #Hfile
UserForm1.TextBox1.Text = sStr
UserForm1.Show
End Sub

give it a try.

--
Regards,
Tom Ogilvy

"JaiJai" wrote in
message ...

Yes, I have tried the all and it really time consuming to read and write
line by line.
The attached file is the text file (large file size) that I want to put
on the textbox.

Are there any other good methods ?


+-------------------------------------------------------------------+
|Filename: CSV-htaa.zip |
|Download: http://www.excelforum.com/attachment.php?postid=3653 |
+-------------------------------------------------------------------+

--
JaiJai
------------------------------------------------------------------------
JaiJai's Profile:

http://www.excelforum.com/member.php...o&userid=19484
View this thread: http://www.excelforum.com/showthread...hreadid=340711



  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding text file to a user form?

Make sure Multiline is set to true for the textbox. Also, probably want to
display the vertical scrollbar.

Private Sub CommandButton1_Click()
Dim sStr As String
strFile = "C:\Data6\CSV-htaa.txt"
Hfile = FreeFile

Open strFile For Input As Hfile
i = LOF(Hfile)
sStr = Input(i, #Hfile)
'Debug.Print Len(sStr)
Close #Hfile
With UserForm1.TextBox1
.MultiLine = True
.ScrollBars = fmScrollBarsVertical
.Text = sStr
End With
UserForm1.Show
End Sub

--
Regards,
Tom Ogilvy

"JaiJai" wrote in
message ...

Yes, I have tried the all and it really time consuming to read and write
line by line.
The attached file is the text file (large file size) that I want to put
on the textbox.

Are there any other good methods ?


+-------------------------------------------------------------------+
|Filename: CSV-htaa.zip |
|Download: http://www.excelforum.com/attachment.php?postid=3653 |
+-------------------------------------------------------------------+

--
JaiJai
------------------------------------------------------------------------
JaiJai's Profile:

http://www.excelforum.com/member.php...o&userid=19484
View this thread: http://www.excelforum.com/showthread...hreadid=340711



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
Adding items to a combo box on a user form Gazz_85[_2_] Excel Discussion (Misc queries) 1 July 9th 09 05:00 PM
Adding a new text box to user form Marilyn Excel Discussion (Misc queries) 3 May 13th 07 11:42 PM
How to input file name in user form Boris Pelakh Excel Programming 1 November 7th 04 07:56 PM
Adding a counter to a User Form in Excel Pam Excel Programming 2 August 17th 04 02:55 PM
Adding items to a spreadsheet from a user form listbox aet-inc[_4_] Excel Programming 1 December 3rd 03 05:13 AM


All times are GMT +1. The time now is 02:33 PM.

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

About Us

"It's about Microsoft Excel"