Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Jun 2002
    Location
    London UK
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating a custom dialog for doc properties (Word 2003 on XP Pro)

    Please can someone point me in the right direction. I'd like to learn how to do something that I have seen done elsewhere, and probably involves some VB scripting and some macros.

    I don't expect someone here to give me step-by-step instructions, because this is a complicated request, but I would really appreciate some pointers to web sites or books where I could learn about how to tackle this challenge.

    What I'd like to do is create a custom dialog box that runs when a user starts to create a new Word document based on a specific template. The user enters his name, the document title, and various keywords. These entries populate Word's Properties dialog. In turn the document based on the template includes document information fields that reference the properties dialog, so that, for example, the document title which the user enters in the dialog appears automatically in the document header.

    Thanks very much for any suggestions you may have,

    David Farbey
    London UK

  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: Creating a custom dialog for doc properties (W

    Those dialogs are called UserForms or UserForm objects. In addition to resources previously recommended in the Lounge, Microsoft's MSDN site has an online version of the manuals that come with the Office Developer Edition. Those should include information about UserForms, as well as the DocumentProperty objects and collections. As for inserting document properties into your document, there is a handy DOCPROPERTY field code.

  3. #3
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating a custom dialog for doc properties (Word 2003 on XP Pro)

    First, put the the DOCPROPERTY fields you want in your document (in the header and such).

    With the template open (as a template, not a document), go to Tools -> Macro -> Macros. Choose "YourTemplate.dot" (or whatever the name of your template is) in the "Macros in" field.

    Type AutoNew in the Macro Name field, and press create.

    The Visual Basic editor opens, and you'll see something like:

    <pre>Sub AutoNew()
    '
    ' Macro created 7/27/04 by David

    End Sub
    </pre>


    Modify that macro so that it reads as follows:
    <pre>Sub AutoNew()
    Dim dial As Dialog
    Set dial = Dialogs(wdDialogFileSummaryInfo)
    Do
    dial.Display
    If (Len(dial.Title) <> 0) And _
    (Len(dial.Subject) <> 0) And _
    (Len(dial.Author) <> 0) And _
    (Len(dial.Keywords) <> 0) Then
    dial.Execute
    Exit Do
    End If
    Loop
    ActiveDocument.Fields.Update
    End Sub
    </pre>

    Save and close your template, and then make a new document off it to try it out.
    This dialog has five relevant properties:
    Title
    Subject
    Author
    Keywords
    Comments

    The macro as written, which will run when a new document is created from the template, won't let the dialog go away until all except the comments field have some value in them. Once they do, those values are assigned to the corresponding document properties, and will appear in the fields.

  4. #4
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating a custom dialog for doc properties (Word 2003 on XP Pro)

    As a P.S. to my previous post (directed to no one in particular) -- It is my opinion that whenever possible (i.e., not plagued by MS bugs), it is always better to use a built-in dialog than to create a new user form. Others may certainly disagree, but I've almost always found it faster and easier to validate the input provided by a built-in dialog than to create a new one. <img src=/S/2cents.gif border=0 alt=2cents width=15 height=15>

  5. #5
    New Lounger
    Join Date
    Jun 2002
    Location
    London UK
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating a custom dialog for doc properties (Word 2003 on XP Pro)

    Andrew,

    Thank you very much, you made that much easier than I had imagined.

    Many thanks,

    David Farbey
    London UK

  6. #6
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating a custom dialog for doc properties (W

    <hr>Microsoft's MSDN site has an online version of the manuals that come with the Office Developer Edition.<hr>
    Jefferson,

    We're upgrading from Win98/Off97 to WinXP/Off2003 and I thought this might come in handy. But I couldn't find those manuals.
    Could you please be a little bit more specific?

  7. #7
    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: Creating a custom dialog for doc properties (W

    Hope these work: Here's the current front page for 2003: Microsoft Office Developer Center, and the library home page for Office Developer XP. Some of the Office 2000 stuff, while a bit dated, might be useful for various projects. You can get there from here.

  8. #8
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating a custom dialog for doc properties (W

    <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>

Posting Permissions

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