Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 33

Thread: Solved: How to Store Text for Building Documents

  1. #1
    VBAX Regular village_alchemist's Avatar
    Joined
    Jul 2004
    Location
    Michigan, US
    Posts
    32
    Location

    Question Solved: How to Store Text for Building Documents

    Hey all!

    Looking for some recommendations from the Guru's here! I've been tasked with automating the creation of a document from selections/responses on a form. I've created the form in MS Word 2000 and it is complete and working. Now all I have to do is create the document based on the responses. I've got a question about how/where to store the formatted paragraphs that will be used in the final document.

    1) Put all possible paragraphs in the template and delete what I don't need
    2) Put the text in the VBA code somewhere
    3) Keep the text in a separate document and paste in as needed
    4) a better way???

    This document creator will need to be used by a number of people accross the country and they won't necessarily be logged into the company network, so I'm trying to keep the number of files that have to be distributed down. On the other hand, changes will need to be made to the text occasionally so ease of modifying text (by a non-programmer) is also a consideration.

    The final document can't contain any macros since it will be sent to other people outside of the company.

    Any suggestions?

  2. #2
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Could you describe your final document more? What does it contain besides the data? Other stuff?

    To begin without further help, you might want to look into INCLUDETEXT in help or on the web.

    And, we have a macro that strips a file of all VBA, so you can use VBA, then strip before sending? Maybe?
    http://www.vbaexpress.com/kb/getarticle.php?kb_id=64

    But you should be able to get more help right here if you can describe that final doc a little better.
    ~Anne Troy

  3. #3
    VBAX Regular village_alchemist's Avatar
    Joined
    Jul 2004
    Location
    Michigan, US
    Posts
    32
    Location
    I'm not sure that includetext will help unless I change the filename or bookmark in the field constantly. I also don't know how many text "snipits" I'll need to add until after the user has completed the form. Hopefully I'll explain better below.

    I saw that VBA stripper macro, that's cool! I could either use that or create a completely new document using the normal template.

    So, more info on the actual document itself. The form prompts the user for some background information such as company, software, etc. Then on the second page of the form there are about 20 checkboxes for standard features that could be added to the customer's software. The user could pick any number of them, from 1 to all. Then the user will press the "Create Doc" command button and *poof*, the document should appear.

    The document is set up with a background section where some of the text the user entered is placed.

    Then there is a details section. This is where separate paragraphs are placed that describe each feature that the user selected on the form.

    There is a customer responsibility section where some text may be placed. For instance, if we are adding another workstation to the system and the customer is supplying the hardware, we have a standard hardware configuration that is normally pasted in.

    There are other sections that are similar, but the fun one is where I have to calculate the cost. Each checkbox has an associated cost and I need to be able to total up the total cost for all the selected checkboxes and insert the total.

    I hope this helps!

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You could put the text into a text file and retrieve it as needed. But the users would have to keep the text file on their computer. Maybe a better option would be to declare your text as a constant in VBA then use it throughout as needed. Once the final doc is created, strip out the VBA code. Something like this perhaps:

    [VBA]
    Option Explicit

    Public Const Text1 = "This is Text1"
    Public Const Text2 = "This is Text2"
    Public Const Text3 = "This is Text3"
    Public Const Text4 = "This is Text4"

    Sub Test()

    Dim Choice As VbMsgBoxResult

    Choice = InputBox("What Do You Want? (1-4)")
    Select Case Choice
    Case Is = 1
    MsgBox Text1
    Case Is = 2
    MsgBox Text2
    Case Is = 3
    MsgBox Text3
    Case Is = 4
    MsgBox Text4
    Case Else
    MsgBox "Invalid selection, input a number from 1 to 4"
    End Select

    End Sub
    [/VBA]

  5. #5
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Actually, this is the PERFECT method. Maybe you won't use INCLUDETEXT, but you *can* create a bunch of Word docs. Then, have option buttons, and if ticked, Doc1 is included, then Doc2, Doc 3 is skipped, etc.

    I've got some code that does that, but it was for a (HUGE) HVAC company (gee, can you guess their name? It starts with H...), but maybe Jake can alter it to suit your purposes?
    ~Anne Troy

  6. #6
    VBAX Regular village_alchemist's Avatar
    Joined
    Jul 2004
    Location
    Michigan, US
    Posts
    32
    Location
    Thanks for the suggestions Dreamboat & DrJ! I've got about a week to get this running, so if I get coderblock I'll be posting again!

  7. #7
    VBAX Tutor
    Joined
    May 2004
    Location
    Germany, Dresden
    Posts
    217
    Location
    As I'm looking for such a thing myself, I'm very interested in this thread.
    But unfortunately none of these solutions seem fitting:
    DRJ: I need to store formatted text
    Dreamboat: I need to have all options in 1 document

    + I need the possibility to restart the form and select other passages, so deleting the text won't be an option either.

    So far I came up with having all text inside the document and just hiding the unecessary passages.

    But I'm not too happy with this solution either, because some documents use print macros that hide/unhide parts of the document, so this collides with the hiding I implemented.

  8. #8
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Steiner

    Maybe you would be better off to have a userform in Excel run through the choices and have the formatted data stored in a sheet. Then you can copy/paste the specified data into Word.

    See here for reference in controlling Word from Excel.

    http://www.vbaexpress.com/kb/getarticle.php?kb_id=81

  9. #9
    VBAX Regular village_alchemist's Avatar
    Joined
    Jul 2004
    Location
    Michigan, US
    Posts
    32
    Location
    Steiner,
    My text is also formatted with both numbering and bullets. The problem I've run into with just a manual copy and paste (with the formatting in both docs being exactly identical) is that Word has a tendency to format the way *it* wants to, not the way *I* changed it to. So after pasting in the section, I have to go back and remove tab stops that are not in the style. Admittedly, I did change the formatting on some pre-defined styles, so I have to test this on user-defined styles.

    I am also concerned about the hidden text, and I can't depend on my users keeping 20 files updated. I'm actually leaning toward having the template contain all of my formatted text and then creating a *new* document to copy the text into. Well, if I can get over this problem of Word re-formatting my text. Otherwise I'll probably go with deleting the sections I don't need.

    The Excel idea is interesting though and that would also allow me to associate a cost with each feature.... Hmmmmmmm

  10. #10
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    No, no, no. LOL!!

    DRJ or even Steiner, I am sure you guys can do this.

    Make one main Word doc. It has a TOC, and all that.
    Make 10 Word docs that contain the various pieces.
    All the docs should be created using the same styles.
    Analogy: I'm buying a car and there are 10 options. You are going to make me a manual that ONLY covers the options I'm buying.

    So, open main doc, userform pops up.
    There's a few textboxes to fill in.
    There's 10 radio buttons for the options.
    I tick 3 of them.
    I hit Submit.

    Each of the 3 Word docs is inserted into my main document (using Insert-File) at either the end of the main doc, and in the appropriate order, OR they are inserted at bookmarked locations in my main doc.

    I'm certain this is what you guys want...
    ~Anne Troy

  11. #11
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    I found it!!
    I'm pretty sure this was created by smozgur.
    Just put the file and the folder both on your desktop, then open the doc.


    Edit: The password is pumpkin
    ~Anne Troy

  12. #12
    VBAX Regular JOrzech's Avatar
    Joined
    Jun 2004
    Location
    Upstate New York
    Posts
    83
    Location
    I use AutoText....
    Joanne

  13. #13
    VBAX Regular village_alchemist's Avatar
    Joined
    Jul 2004
    Location
    Michigan, US
    Posts
    32
    Location
    Wouldn't the use of AutoText require that each user have the AutoText definitions in their local application?

  14. #14
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Hey Dreamy, that's a pretty nice file. Is it in the kb yet?

  15. #15
    VBAX Regular JOrzech's Avatar
    Joined
    Jun 2004
    Location
    Upstate New York
    Posts
    83
    Location

    AutoText

    Quote Originally Posted by village_alchemist
    Wouldn't the use of AutoText require that each user have the AutoText definitions in their local application?
    I simply store all the AutoText entries in the template itself.
    Joanne

  16. #16
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Jake: Nope. I'm not the coder of that file...and wouldn't know the first thing...
    Go ahead!


    But!
    I'd rather we put TWO methods (even 2 kb entries). One that uses the documents, and one that uses autotext.

    JO is right about using autotext and, for the life of me, I can't remember why autotext wouldn't work for the client for which that sample was created. I *think* it's because they had different people in charge of the individual documents and didn't want to have to touch the template every time 'cause it was used too much for such disruptions.
    ~Anne Troy

  17. #17
    VBAX Regular JOrzech's Avatar
    Joined
    Jun 2004
    Location
    Upstate New York
    Posts
    83
    Location
    Here's the code I use to insert the AutoText - this is how I assemble many of the templates at my firm:

    [VBA]
    ActiveDocument.AttachedTemplate.AutoTextEntries("Whatever").Insert _
    Where:=Selection.Range, RichText:=True
    [/VBA]

    BTW - you need to have the RichText:=True at the end, otherwise, you lose the styles.


    HTH
    Joanne

  18. #18
    VBAX Regular village_alchemist's Avatar
    Joined
    Jul 2004
    Location
    Michigan, US
    Posts
    32
    Location
    Quote Originally Posted by JOrzech
    I simply store all the AutoText entries in the template itself.
    A big thumbs up to Joanne! And a big D'oh! from me. I started in that direction, but then abandoned it because the autotext showed up in my normal template. Amazing what happens when you use those drop down boxes....

    Thanks for the "Quoter" snippit, Dreamboat. It reminded me that I need to password my code. Small world, my wife worked for AlliedSignal in Morristown, NJ when "H" purchased them.

  19. #19
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    My brother-in-law works for them now...
    ~Anne Troy

  20. #20
    VBAX Regular JOrzech's Avatar
    Joined
    Jun 2004
    Location
    Upstate New York
    Posts
    83
    Location

    I am so pleased....

    Village_Alchemist.... so glad it worked out for you! We often don't see the forest for the trees! Those dang dropwdown boxes can be very confounding
    Joanne

Posting Permissions

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