Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Jul 2003
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Auto-create document (Word 2003)

    Hi,

    I want to create a template wich auto-fills a document wich certain text blocks. For example:

    A users opens the word-template. Automatically he/she get's a pop-up screeen where he can enable some check-boxes. Each check-box stands for a specific piece of text. When he's ready doing that he pushes some kind of generate button and according to the checkboxes the document is automatically created.

    Can anyone give me some hints or tips how to create such a template?

    tnx,
    Gerben

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Auto-create document (Word 2003)

    The pop-up screen would be a userform. You create a userform in the Visual Basic Editor, by selecting Insert | UserForm. The Toolbox contains controls you can place on the form, such as check boxes, command buttons etc.

    You would display the userform from an AutoNew macro in a standard module or from the Document_New event handler in the ThisDocument module, for example

    Private Sub Document_New()
    UserForm1.Show
    End Sub

    The blocks of text could either be contained in the code, or could be AutoText entries stored in the template. Example code:

    Selection.TypeText Text:="This is the first paragraph in a block of text."
    Selection.TypeParagraph
    Selection.TypeText Text:="This is the second paragraph in the block."
    Selection.TypeParagraph

    or

    ActiveDocument.AttachedTemplate.AutoTextEntries("B lock1").Insert Where:=Selection.Range, RichText:=True

  3. #3
    Lounger
    Join Date
    Jul 2003
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Auto-create document (Word 2003)

    Thanks Hans,

    It gives me some first ideas how to make my template. The idea is to present the user a UserForm where he fills in the name of the customer, he can select some chechboxes (wich inserts parts of text), fill in the number of products the customer wants etc. When that has been al filled in, I want to click a command button to execute all my choices.

    Maybe you have me some example document (or a link).

    thanks

    Gerben

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Auto-create document (Word 2003)

    If you do a search for userform in this forum, you will find many threads dealing with them. For example, look at the replies in the thread starting at <post#=340997>post 340997</post#>.

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

    Re: Auto-create document (Word 2003)

    An alternate way of doing this is to use IF fields in the document and refer to items in the document properties to show or not show the text in the IF fields. This is Word's equivalent to Framemaker's conditional text.

    An example would be {If {DocProperty Title}="Superbowl" "Show me the money" "No money here"} where the brackets are inserted using the Ctrl-F9 keystroke.

    This will avoid having to create a user form and do all the coding along with it. It will rely on the user setting the (custom?)document properties and then updating the fields. Before you deliver the file to a customer, you should probably break all the field links so that they can't see what else they might have been offered.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

Posting Permissions

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