Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 33 of 33

Thread: Solved: How to Store Text for Building Documents

  1. #21
    VBAX Tutor
    Joined
    May 2004
    Location
    Germany, Dresden
    Posts
    217
    Location
    @Dreamboat: Hey, how I'm supposed to take this one:

    DRJ or even Steiner


    And as I said, I don't like the idea of having lot's of documents hanging around. But Joannes suggestion about the autotext sounds promising, I think I'll go for that one, thanks Joanne !

  2. #22
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Sorry, Steiner. No insult intended!
    I just know that DRJ is really a WHIZ at code!
    ~Anne Troy

  3. #23
    VBAX Regular JOrzech's Avatar
    Joined
    Jun 2004
    Location
    Upstate New York
    Posts
    83
    Location
    @ Steiner

    You're welcome! Glad to have been of some help....
    Joanne

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

    Is this question "solved" ?

    Anything else?
    Joanne

  5. #25
    VBAX Regular village_alchemist's Avatar
    Joined
    Jul 2004
    Location
    Michigan, US
    Posts
    32
    Location
    Hi Joanne!
    No other questions on this thread. I actually used a combination of suggestions from different threads here to come up with the final solution. Everyone here has been very helpful! I'm actually using a combination of Bookmarks, AutoText, and CustomDocumentProperties.

    One trick that I used was to be consistent between my form's control names, and the template's Bookmarks, AutoText, and CustomDocumentProperties names. This allowed me to use the control name (or part of it) to access the correct template item. This way as I loop through the controls on my form I don't have to have a separate test condition for each item.

    Here is how my final solution works:

    For text that the user enters that goes in a fixed position in the document, I used a TextBox for the user to enter the information and then I print it at a bookmark that is defined in the template.

    CheckBoxes and OptionButtons add text to the document using AutoText entries that contain pre-formatted lines or paragraphs. These controls also access the CustomDocumentProperties which holds the 20 different values for the 20 different options. Following is a simplified snipit:

    [VBA]
    For Each ctlInForm In MyForm.Controls

    Select Case TypeName(ctlInForm) 'MUCH more reliable than TypeOf function

    Case "TextBox" 'value stored in .Text property
    Selection.GoTo what:=wdGoToBookmark, Name:=ctlInForm.Name
    Selection.TypeText ctlInForm.Text
    Case "CheckBox", "OptionButton" 'value stored in .Value property
    If ctlInForm.Value Then
    Selection.GoTo what:=wdGoToBookmark, Name:=ctlInForm.Name
    ActiveDocument.AttachedTemplate.AutoTextEntries _
    (ctlInForm.Name).Insert _
    where:=Selection.Range, _
    RichText:=True

    'add the time required for this item
    iTotalTime = iTotalTime + _
    ActiveDocument.CustomDocumentProperties(ctlInForm.Name)
    End If
    End Select

    Next ctlInForm
    [/VBA]

  6. #26
    VBAX Regular JOrzech's Avatar
    Joined
    Jun 2004
    Location
    Upstate New York
    Posts
    83
    Location
    Very nice! Glad you got it all pulled together
    Joanne

  7. #27
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Could you not store the text as bookmarks (ranges that include the text). That way you could have a drop down (and I think an ActiveX combobox would be better. You could select whatever chucnks are appropriate and go from there. Or am I missing something....woudn't be the first time.

  8. #28
    VBAX Regular village_alchemist's Avatar
    Joined
    Jul 2004
    Location
    Michigan, US
    Posts
    32
    Location
    Each of the 20 or so selections on the form may generate paragraphs in multiple sections of the document. We've had this template set up so the user could just do an "Insert | File" for about 6 months and have had no end of missing text and extra text. Much better (and faster) for the user to click a CheckBox for the option they want and have the template validate the entries to be sure they don't contradict and also place the correct text in the correct positions.

  9. #29
    VBAX Regular JOrzech's Avatar
    Joined
    Jun 2004
    Location
    Upstate New York
    Posts
    83
    Location
    fumei may be correct.... but we all get into our own habits of coding that are comfortable for us. I don't use bookmarks as ranges... I simply add a bookmark and go to that bookmark and add the appropriate autotext entry. I don't know what the construction of your document is, but if it's just straight text I don't know why text boxes would be needed, you may make it simpler by using something like this:

    [vba]
    Selection.GoTo what:=wdGoToBookmark, Name:="YourBookmarkName"
    ActiveDocument.AttachedTemplate.AutoTextEntries("YourAutoTextEntry").Insert _
    Where:=Selection.Range, RichText:=True
    [/vba]

    Maybe I'm the one missing something? In any event, it's working well for village_alchemist and he's blended a lot of suggestions into one working app, so I'm pleased. I guess there's always a better mousetrap
    Joanne

  10. #30
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location

    Text Select

    I note the thread is solved, but here's another approach using Excel to store your data; suitable for very large amounts of text options. Extract the files into C:\Amerge. Use the macrobutton (you may need to toggle this) to open a userform. Select the item in the listbox, double click to place it in the document. It's a Work In (occasional) Progress; suggestions welcome.
    MD

  11. #31
    VBAX Regular JOrzech's Avatar
    Joined
    Jun 2004
    Location
    Upstate New York
    Posts
    83
    Location
    That's nice md! I personally think it's easier to check a checkbox on a VBA user form and have the autotext inserted... but it's a really neat little program. I seem to recall seeing something similar at one point for a document assembly program. You may be on to something $! Is there any limit to the descriptive language you can give to the modules that are inserted?
    Joanne

  12. #32
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Joanne,
    Only to the extent that the text is displayed in the listbox. I don't think the listbox will wrap and display long descriptions. Happy to be wrong though.
    MD

  13. #33
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Joanne's suggestion works fine. However here is what I did for a real situation. I work with documents that MUST have both english and french text. Rather, the user must have a choice of working in french or english.

    I had to create a financial form in Word that would generate documents that had a huge bunch of details. The details were different based on whether the user was selecting a Journal Voucher transaction, a Cost Recovery transaction, whether the course that was being asked for was previously paid for out of someone else's budget - in other words lots of multiple choices.

    Here is what I did.

    ONE document, with multiple sections each one carefully bookmarked.

    On open - First user form asked "English or French?".

    From that (with screen updating off of course), the result picked out the range of the sections NOT applicable. if french selected, all english sections were removed, and vice versa.

    This left the sections specific to the what type of transactions were possible (but only those for the language chosen).

    The second user form displayed and the user selected the type of transaction. I did not use a third form. The controls on the form were set for invisible until user selected transaction type. When they do, all the controls appeared (Student name, course cost, supervisiors name, phone number, course start/end date, etc etc etc.) Meanwhile, as the type of transaction is now known, the code removed all the sections (using the bookmark ranges) that were not appropriate. If a JV transaction - the Cost recovery section was removed etc.

    User typed in their information, pressed OK, all the information ran through a huge error trapping routine, and if passed, dumped the information into the appropriate formfields, in the appropriate section. Document automatically saved as FinancialRequest_username.

    Original document remained intact and quite reuseable. Note this was a document, NOT a template. Therefore it did not require explaining that it had to be copied into a template folder, did not have to be called via File, New. They could just open the file, and everything ran. All code remained in original. All code stripped from the saved as.

    Oh, and as further lock, when the document finished, it inserted a final bookmark that had a result "Done". If the saved as file is opened again, the Opening routine checked for the "Done" bookmark. If found, it bypassed the opening language choice and displayed another userform that allowed either editing or creating a new document. If editing was chosen, the document (the saved as) opened for editing, if create a new chosen, the saved as file would open the original (making it active), code in the original would pick up the savedas filename, close it and delete it.

    On the original processing I disabled ALL exits, even the little X that closes the userform. The user had to complete the form, although i gave them the choice to exit completely. In which case the original document closed automatically, which no processing or changes.

    Sounds more complicated that it was. Original document had 8 sections (four for each language) and always ended up with one - the section for the transaction type in the language of their choice.

Posting Permissions

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