Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    4 Star Lounger
    Join Date
    May 2003
    Location
    Austin
    Posts
    401
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Export data to txt file

    How do you create a procedure that exports data from text boxes in a UserForm to a tab-delimited text file?
    The trick is I must append tags that are to be used for the styles of the next application (i.e. Pagemaker)

    I've attached the .txt file with the desired results.
    Attached Files Attached Files

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Export data to txt file

    Outputting to a text file is relatively straightforward. Here's some sample code that creates a batch file:

    <pre>Dim FileNo As Integer
    FileNo = FreeFile
    Open "c:Backup1.bat" For Append As #FileNo
    Print #FileNo, "@ECHO Off" 'turn off console echo
    Print #FileNo, "REM Created " & Format(Now, "mmm d, yyyy hh:nn:ss AM/PM")
    Print #FileNo, "REM By BuildBackup1 Macro/MakeBack2001 [JFS 2/04/2001]"
    Print #FileNo, "ECHO."
    Print #FileNo, "ECHO Please close any open documents and exit Outlook..."
    Print #FileNo, "ECHO When you are ready to back up, return to this..."
    Print #FileNo, "ECHO."
    Print #FileNo, "ECHO If you don't want to back up now, ... Otherwise,"
    Print #FileNo, "ECHO."
    Print #FileNo, "Pause"
    Print #FileNo, "c:" 'change drives to C drive
    If strWordDocs <> "" Then 'backup changed files
    Print #FileNo, "cd " & strWordDocs
    Print #FileNo, "XCOPY *.* " & strBackPath & "WORDDOCS /m/s/f/v/y"
    End If
    ...
    Print #FileNo, "ECHO."
    Print #FileNo, "ECHO *** Backup completed ***"
    Print #FileNo, "Pause"
    Close #FileNo
    </pre>

    If you paste this into a VBA procedure and view the online help, all should become clear. Hope this helps.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Export data to txt file

    There are two parts to this process:

    1: grabbing the text from the user form
    2: writing the text to a file.

    For part "2", In the VBA forum I'm posting my PrintFile function, and my LogFile function which shows a use of printfile. Look in the VBA forum for a message subject "Code: PrintFile".

    How are you going about part "1"? Are you able to grab the text (that can then be passed to printFile or similar) or do you need feedback on that?

  4. #4
    4 Star Lounger
    Join Date
    May 2003
    Location
    Austin
    Posts
    401
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Export data to txt file

    I could use help on that too since I am a novice at this.

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Export data to txt file

    Soo.. grab those two procedures, but especially PrintFile, and play with that as a means of writing data to a text file.

    My earlier question still holds: How are you (two) going about obtaining the data that you want to write to a text file?

  6. #6
    4 Star Lounger
    Join Date
    May 2003
    Location
    Austin
    Posts
    401
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Export data to txt file

    The data is being entered via A Word UserForm. There are several variants of the UserForm, which is intended to 'guide' the User down the path of entering correct data, such as an email fork in the program which reveals a form that has an email address in a specific place, and has only a text box for their name so that's the only part they can mess up in the email addie.

    There will only be one form per user for data entry.

    The current procedure is to save the files as a text file and title it with their name. I would like to automate the procedure and just have them fill in the 'Save as' and save in box.
    There will also be several additional fields that hopefully will assist in the process of the final output
    -Getting this data into a professional printing package like Pagemaker.
    Still looking into that one...Know anything about Publisher?

  7. #7
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Export data to txt file

    The easiest way to get styles into a page layout program is going to involve adding the text from the forms into a Word document type (or RTF) and put the styles on there. Then Pagemaker will import the text with the styles already there. I can only hope that Publisher does the same.

    If you have a look at the RTF file then you will see what a style tag needs to look like for the Page Layout program to import it.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  8. #8
    4 Star Lounger
    Join Date
    May 2003
    Location
    Austin
    Posts
    401
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Export data to txt file

    The current procedure has the customer save the file with the tags already in place that Pagemaker uses to set the styles.
    I wanted to implement the UserForm and concatenate the styles to the textbox data, so that the final product would be the tags with the data e.g.
    <Name> John Doe
    <District> East
    <Address> 1313 Mockingbird Lane
    {et al} There are a total of 9 lines available, but that varies with the data supplied.

    The ultimate goal would be for this data to somehow get into a database, which is easily done.
    The dream is for it to create a grid of 12 cards, landscape format, 3 across and 4 down. The order is determined by the number of times an impression is needed. Each impression = 200 cards. If a customer needed 600 cards, the grid would have 3 cards on the grid or 1 for each 200 prints.

    This is going to a 4 color professional printing press, so printing to spec is crucial. PageMaker has that kind of 'discipline' (i.e. leading and kerning) and Word doesn't support 4 color separation.
    Hence, my query about MSPublisher.
    Thanks

  9. #9
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Export data to txt file

    By "user form" do you mean a GUI (used to be caleld a Dialogue Box in Word2/6) or do you mean those dreadful forms where you lose all your data if you unprotect/protect the form?


    If it's a GUI form, you'll have a "save data" button, or an "OK" button. The click event for this button will have code that assembles a string of text to be sent to the PrintFile procedure, somewhat like this:

    dim strOut as string
    strOut=""
    strOut=strOut & me.txtBox1
    strOut=strOut & me.txtBox2
    strOut=strOut & me.txtBox3
    etc.

  10. #10
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Export data to txt file

    Chris

    Don't let Geoff catch you bad-mouthing Word Forms [img]/w3timages/icons/grin.gif[/img]

    You do know that a macro will stop the data from being cleared don't you?
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  11. #11
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Export data to txt file

    Sorry Andrew, I've already caught him [img]/w3timages/icons/laugh.gif[/img].

    Hey, they've got there place- and our site loves them. I don't really, because if I was developing with fully-blown Userforms instead of Word forms, I'd be full-time on Word, not just one day a week.

    And as for the protect "feature"- as you say, a macro will stop them from being cleared.

    A catch is, that if you use the Word built-in dialog for protecting a form (for forms, refvisions etc) you don't have access to all the built-in properties as documented. So I've got a little userform to do the same.

    Fairly straight-forward but is anyone interested? Or am I the only exponent of Word forms around?
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  12. #12
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Export data to txt file

    >Don't let Geoff catch you bad-mouthing Word Forms

    OK. here's some GOOD stuff about forms :


    Ummm.


    Huh-ummm.



    Darn!




    OK. Forms DO have their uses, but I bet that AT LEAST 50% of the queries in any forum/help desk are about "losing my data" when unprotected. For that reason alone we ought to be sounding a caveat to users.

    And yes, thank you, I'm one of the lucky ones who learned the work-around (I think it was available for Word6) and I LIKE that because it guides people into the view that hey, this programming thing could be useful.

  13. #13
    4 Star Lounger
    Join Date
    May 2003
    Location
    Austin
    Posts
    401
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Export data to txt file

    While most of those forms are indeed the dreaded, 'clumsy' unprotect-protect version, I am trying to get the GUI stuff implemented.
    Most of our macros are based on Wordbasic if that helps you evaluate the situation any;-)

  14. #14
    4 Star Lounger
    Join Date
    May 2003
    Location
    Austin
    Posts
    401
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Export data to txt file

    I thought just by adding *this snip* at the line of: WordBasic.ToolsProtectDocument *NoReset:=1, Type:=2* would hold data from erasing when locking/unlocking the fields.

    What's the modern equivalent?
    Speaking of updating archaic procedures...
    Looking at the code of these things makes me wonder why every sub is called MAIN. What's that about?

  15. #15
    4 Star Lounger
    Join Date
    May 2003
    Location
    Austin
    Posts
    401
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Export data to txt file

    How does your PrintFile function call this strOut procedure? Or actually, vice verse since it's tied to the cmd_button.

    I can't even get the function to be recognized.

Page 1 of 2 12 LastLast

Posting Permissions

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