+ Reply to Thread
Results 1 to 11 of 11

Adding text file to a user form?

  1. #1
    Chip
    Guest

    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. #2
    Tom Ogilvy
    Guest

    Re: 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" <cneuman@gmail.com> wrote in message
    news:1107194913.527134.9130@c13g2000cwb.googlegroups.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. #3
    Chip
    Guest

    Re: 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. #4
    Chip
    Guest

    Re: Adding text file to a user form?

    By the way, Tom you are the man


  5. #5
    Tom Ogilvy
    Guest

    Re: 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" <cneuman@gmail.com> wrote in message
    news:1107197908.510308.152400@f14g2000cwb.googlegroups.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. #6
    Tom Ogilvy
    Guest

    Re: Adding text file to a user form?

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

    --
    Regards,
    Tom Ogilvy

    "Tom Ogilvy" <twogilvy@msn.com> wrote in message
    news:urpiwp8BFHA.1392@tk2msftngp13.phx.gbl...
    > 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" <cneuman@gmail.com> wrote in message
    > news:1107197908.510308.152400@f14g2000cwb.googlegroups.com...
    > > I'm not sure what you mean? How would I go about doing that? Any code
    > > to get me started would be great.
    > >

    >
    >




  7. #7
    Chip
    Guest

    Re: Adding text file to a user form?

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


  8. #8
    Tom Ogilvy
    Guest

    Re: 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" <JaiJai.1su8ka_1122484185.9191@excelforum-nospam.com> wrote in
    message news:JaiJai.1su8ka_1122484185.9191@excelforum-nospam.com...
    >
    > 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
    >




  9. #9
    Tom Ogilvy
    Guest

    Re: 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" <JaiJai.1sw0eu_1122566784.0114@excelforum-nospam.com> wrote in
    message news:JaiJai.1sw0eu_1122566784.0114@excelforum-nospam.com...
    >
    > 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
    >




  10. #10
    Tom Ogilvy
    Guest

    Re: 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" <JaiJai.1sw0eu_1122566784.0114@excelforum-nospam.com> wrote in
    message news:JaiJai.1sw0eu_1122566784.0114@excelforum-nospam.com...
    >
    > 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
    >




  11. #11
    NickHK
    Guest

    Re: Adding text file to a user form?

    JaiJai,
    Just put the whole file into a RichTextBox ?

    NickHK

    "JaiJai" <JaiJai.1su8ka_1122484185.9191@excelforum-nospam.com> wrote in
    message news:JaiJai.1su8ka_1122484185.9191@excelforum-nospam.com...
    >
    > 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
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1