Results 1 to 7 of 7
  1. #1
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Inserting fields into filename & property (2003 (11.0))

    Hi all

    I've created a simple form for collecting basic document information at the time of creation (client, contact, title, etc). It works fine, and plugs these values into a header section of the document exactly as I want it to.

    But I'd like to take my Autonew macro a couple of steps further with the following:

    1. Initiating File Save (easy enough)

    2. Concatenate 2 of the fields (arbitrarily called "title" and "version") to create a filename (e.g. "Brochure copy 1.1"), so that all I have to do is navigate to the appropriate folder & click OK.

    3. Copy the value of my "title" field into the document's "Title" property.

    That's ambitious enough for now. When I learn how to achieve this with the kind help of the Loungers, perhaps I'll look into a more automated way of dealing with the version numbering...

    Thanks in advance for any advice you guys can offer.

    All the best

    Neil

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

    Re: Inserting fields into filename & property (2003 (11.0))

    See How to set the default suggested filename to be displayed by the Save As dialog the first time a user saves a new document on the Word MVP site. This shows how to set the Title property in code and set the proposed filename at the same time.

  3. #3
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Inserting fields into filename & property (2003 (11.0))

    Hans g'day

    Thanks for your reply - this has been driving me nuts. Since writing my post, I've been researching and experimenting further. I'm t-h-i-s close to solving it but something is eluding me.

    I have adapted a template and form by Charles Kenyon (bless him) to collect various items of doc info and insert them into bookmarks which appear in the document. The only challenge is taking the contents of two of the bookmarks, concatenating them, and sticking them as the new document subject (so that the File Save As dlg will pick it up).

    But what isn't working for me is this: my command:

    newTitle = ActiveDocument.Bookmarks("Title")

    always applies the literal value "Title" to the variable, instead of the contents of the bookmark called "Title" - I've tried a number variants on the theme but am obviously missing something basic which the caffeine isn't helping me spot.

    Any suggestions as to how I can grab the contents of a bookmark?

    Many thanks

    Neil

  4. #4
    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: Inserting fields into filename & property (2003 (11.0))

    In the Office object model, this code:

    newTitle = ActiveDocument.Bookmarks("Title")

    fills the variable newTitle with the default property of the bookmark. To specify a particular property, tack it on at the end. For example:

    newTitle = ActiveDocument.Bookmarks("Title").Range.Text

    From one object to the next, the default property and the contents will be different! It's somewhat frustrating; the online help can be helpful here.

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

    Re: Inserting fields into filename & property (2003 (11.0))

    The Name property of a bookmark is its default property, so by retrieving a bookmark without specifying a property, you are retrieving its name. To get the contents, use

    newTitle = ActiveDocument.Bookmarks("Title").Range.Text

  6. #6
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Inserting fields into filename & property (2003 (11.0))

    Jefferson

    Bingo... the ".Range.Text" was the holy grail...

    Thanks so much for your help - it's greatly appreciated!

    Cheers

    Neil

  7. #7
    Star Lounger
    Join Date
    Sep 2001
    Location
    Perth, Western Australia
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Inserting fields into filename & property (2003 (11.0))

    Hans

    You posted exactly the same reply as Jefferson Scher at exactly the same time - indeed the ".Range.Text" was what I needed to kick-start this idea.

    Thanks very much indeed for taking an interest and being so responsive.

    Very best regards

    Neil

Posting Permissions

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