Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Linked Custom Properties (97)

    I tried defining a custom document property that was linked to a bookmark. Added the bookmark in the usual way (Insert | Bookmark) such that it included some text. Then went into File | Properties and clicked on the Custom tab. I typed the name of a new property (call it newprop1), checked the Link to Content box and selected my bookmark. Now I inserted a field to refer to my newprop1 property. OK so far. It even showed the value of the bookmark (call it value1)

    Now back in my document, I changed the value of the bookmark to say value2. The reference to newprop did NOT change. OK. Figure I need to update fields, so I selected the reference to newprop1 and clicked F9. Nothing. Hit Shift+F9 to make sure the reference was correct - no problem. It read
    { DOCPROPERTY "newprop1" * MERGEFORMAT }

    Seems correct.

    So I went back into File | Property. Sure enough, in the custom properties listing at the bottom, Word showed a value of value2 for newprop1.

    So back out to Word again. Select the document reference and hit F9 again.

    NOW, it shows value2.

    This can't be the way it's supposed to work, can it? I understand a need for the first F9 to update the field. But why should I have to go thru File | Properties to get this to work? Any diffs in 2000 or XP?

    Thanks.

    Fred

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Linked Custom Properties (97)

    Hi Fred:
    Works the same way in Word 2000. You can close & reopen the document, & that will also update the property.

    My guess is that the document property is not updated until you close Word or view the Properties box, but I couldn't find anything quickly in the Knowledge Base.

    You don't even have to select the custom property in the dialog box & you can even click cancel. In fact, so long as the properties dialog box opens to any tab, it updates. Another (mis)design feature.

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Linked Custom Properties (97)

    Hi Fred & Phil,

    Fred - you really unearthed a whole nest of non-functionality there - MS should have hired you as a tester years ago!

    Phil's mention of the doc properties updating when you close and open the document led me to the following macro workaround - which does work, but only because a bunch of more direct approaches either don't work or aren't available:

    Public Sub UpdateFieldsAndDocProps()
    ActiveDocument.Save
    ActiveDocument.Range.Fields.Update
    End Sub

    (of course, this won't update fields in the headers/footers - more code would be needed to update these)

    The above works because apparently the Document Properties are updated whenever you save the document.

    It's logical enough that F9 alone wouldn't do the trick, since the Custom Doc Property isn't a field. But what's perplexing is why MS doesn't provide any other means for updating the doc properties, other than showiing the File Properties dialog, as Phil noted, or else by saving the file.

    To make matters worse - suppose you'd observed that showing the FileProperties dialog forces the document properties to update - so you try to create a macro to update the properties this way (this is what I did before I got the doc Save idea from Phil).
    With most of the built-in Word dialogs, you can use code something like:

    Dialogs(wdDialogNameOfDialog).Execute

    - the dialog won't display, but effectively you will get results as if you did display it and clicked OK.
    So that would be a good solution, except: it turns out that you cannot access this dialog programatically! - it simply appears to have been left out when they built the Word VBA object model (perhaps someone can point to the undocumented way to make it display).

    Another code workaround in these cases can be to force the dialog to open by using the CommandBars object - but this method leaves the FileProperties dialog open, with no way to close it via code.

    If you try to address a Custom Doc Property directly from code, you'll find that very little functionality was provided in Word VBA for these - there is only one method: Delete!

    So this seems to be an incompletely implemented area, both in the Word userface and when dealing with the Word object model via VBA. <img src=/S/igiveup.gif border=0 alt=igiveup width=31 height=23>

    Gary

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Linked Custom Properties (97)

    Hi Gary:
    That's interesting. Before I posted, I tried saving the file & then updating the doc property field. It didn't update the field...& still doesn't. But your macro sure does. I can't figure out why the macro works but doing the two steps manually (saving & updating the field) doesn't work.

  5. #5
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Linked Custom Properties (97)

    > (of course, this won't update fields in the headers/footers - more code would be needed to update these)

    Here is a copy of the Macro I use to update all fields in all headers and footers in a document...

    <pre>Sub UpdateHeaderAndFooterFields()

    ' Updates all fields in headers and footers throughout the document

    Dim secSection As Section
    Dim hfHeader As HeaderFooter
    Dim hfFooter As HeaderFooter

    For Each secSection In ActiveDocument.Sections
    For Each hfHeader In secSection.Headers
    If Not hfHeader.LinkToPrevious Then hfHeader.Range.Fields.Update
    Next hfHeader
    For Each hfFooter In secSection.Footers
    If Not hfFooter.LinkToPrevious Then hfFooter.Range.Fields.Update
    Next hfFooter
    Next secSection
    End Sub
    </pre>


    StuartR

  6. #6
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Linked Custom Properties (97)

    Phil, Stuart, Gary

    Thks for the efforts.

    Here's more perplexing things-
    After seeing Phil's 1st response, I figured, OK, this is easy. Just record a macro of doing File | Properties and clicking OK. Nothing. I got
    Sub Macro1()
    '
    ' recorded by Fred Burg
    '
    End sub

    OK. Maybe a little more functionality. I added a custom property with a link. Nothing. I added a custom property and gave it a Yes/No value. Nothing. I deleted my custom property. Nothing. I added a new Title. Nothing. Speak of non-functionality.

    Phil: you had a macro (notice I didn't say you wrote it, as you disavowed) on the Update TOC thread that updated all fields. It seems like you may need to include Gary's 2-liner for that.

    Gary: you mentioned:
    >>It's logical enough that F9 alone wouldn't do the trick, since the Custom Doc Property isn't a field.
    Not sure if I understand the entire logic of why it's logical that F9 alone won't do the trick. When I went to Insert | Field, I was able to insert my custom property. If it hadn't been there, I wouldn't have thought of using F9.

    Question for Gary and Stuart:
    if one starts with Phil's macro on the Update TOC thread, adds in the 2-liner from Gary as a separate item (not in any of the loops), would this then do the job of updating ALL fields (I'm including the custom property field as part of ALL)? Gary mentioned needing more code for headers/footers which Stuart provided. My problem is that I'm not familiar with what

    For Each rngStory In doc.StoryRanges
    If rngStory.StoryType = wdCommentsStory Then

    does. That is, not sure what's included in doc.StoryRanges. I thought headers/footers would be included here. If not, then one needs to add Stuart's code to Phil's to update ALL fields. Or are there yet other fields not included in the above (plus the TOx loops in Phil's code). Maybe text boxes?

    Gary: you also had a term in your response - "userface". Is that short for "user interface"? Where did that come from. We abbreviate "user interface" as UI.

    Thanks to all.

    Fred

  7. #7
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Linked Custom Properties (97)

    Gary,

    Thks. See response to Phil's 2nd posting for more questions to you.

    Maybe we need a cc feature on the lounge so that I can reply to 1 person but make sure that others (who might not be moderators and monitoring all the posts) see this.

    Fred

  8. #8
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Linked Custom Properties (97)

    Stuart,

    Thanks for the header/footer update. If still interested in some observations on the Linked Custom Properties, see my response to Phil's 2nd response.

    Also, in looking at your macro, I'm just curious as to why it matters, if you're updating all headers/footers for any fields, whether a header/footer is linked to the previous. If it isn't, fine - you want to update them. If it is, then whatever updates applied to fields in the previous, can be updated in the "current" header/footer w/o any harm (maybe they're already updated by updating the previous?).

    Fred

  9. #9
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Linked Custom Properties (97)

    Gary,

    I guess my comment, in response to Phil, about recording a macro of accessing File | Properties and getting no results is equivalent to you saying that the dialog was left out of the VBA model.

    Fred

  10. #10
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Linked Custom Properties (97)

    Edited to add ActiveDocument.Save to UpdateAllFields macro. Note that it must be added near the beginning of the macro, as you must save before you update the fields.

    Hi Fred:
    I will see about adding Gary's macro lines to the macro I posted. Just a few comments. The macro I posted (UpdateAllFields) does update all the fields in the header/footer, as well as the main document. Of course, now we know it doesn't update custom property fields. The lines regarding comments was put in the macro to suppress an alert that popped up if you had comments in the document & were using Word 2000.

    If you update all fields in Word 2000 & have comments (annotations), a message pops up saying are you sure you want to do this (paraphrasing); it can't be undone. It's a strange alert because 1) it can be undone & 2) it's updating the pageref field in the comment pane (so that if you print comments at the end, they will refer to the correct page).

    I've noticed that trying to record the opening or closing of a dialog box is usually futile. Word will record the results chosen in many dialog boxes, but not opening or closing them.

    I agree that we should have a way to be notified whenever someone posts to a thread in which we have a post, but maybe that's asking for too much. After all, this Lounge has more options & is easier to navigate than any other "message board" I've seen.
    -------------------------------------
    <pre>Public Sub UpdateAllFields()
    '--------------------------------------------------------------------------
    ' Procedure : sUpdateFields
    ' DateTime : 20-Dec-2001
    ' Author : Bryan Carbonnell
    ' Purpose : To Update all fields in the Word Doucument
    ' including TOC, TOA, TOF and Fields in Headers/Footers
    ' & including custom document property fields
    '--------------------------------------------------------------------------
    Dim doc As Document ' Pointer to Active Document
    Dim wnd As Window ' Pointer to Document's Window
    Dim lngMain As Long ' Main Pane Type Holder
    Dim lngSplit As Long ' Split Type Holder
    Dim lngActPane As Long ' ActivePane Number
    Dim rngStory As Range ' Range Objwct for Looping through Stories
    Dim TOC As TableOfContents ' Table of Contents Object
    Dim TOA As TableOfAuthorities 'Table of Authorities Object
    Dim TOF As TableOfFigures 'Table of Figures Object
    ' Set Objects
    Set doc = ActiveDocument
    Set wnd = ActiveDocument.ActiveWindow
    ' get Active Pane Number
    lngActPane = wnd.ActivePane.Index
    ' Hold View Type of Main pane
    lngMain = wnd.Panes(1).View.Type
    ' Hold SplitSpecial
    lngSplit = wnd.View.SplitSpecial
    ' Get Rid of any split
    wnd.View.SplitSpecial = wdPaneNone
    ' Set View to Normal
    wnd.View.Type = wdNormalView
    'Next line allows custom document property_
    'fields to update
    ActiveDocument.Save
    ' Loop through each story in doc to Update
    For Each rngStory In doc.StoryRanges
    If rngStory.StoryType = wdCommentsStory Then
    Application.DisplayAlerts = wdAlertsNone
    ' Update fields
    rngStory.Fields.Update
    Application.DisplayAlerts = wdAlertsAll
    Else
    ' Update fields
    rngStory.Fields.Update
    End If
    Next
    ' Loop through TOC and Update
    For Each TOC In doc.TablesOfContents
    TOC.Update
    Next
    ' Loop through TOA and Update
    For Each TOA In doc.TablesOfAuthorities
    TOA.Update
    Next
    ' Loop through TOF and Update
    For Each TOF In doc.TablesOfFigures
    TOF.Update
    Next
    ' Return Split to original state
    wnd.View.SplitSpecial = lngSplit
    ' Return main pane to original state
    wnd.Panes(1).View.Type = lngMain
    ' Active proper pane
    wnd.Panes(lngActPane).Activate
    ' Close and release all pointers
    Set wnd = Nothing
    Set doc = Nothing
    End Sub</pre>


  11. #11
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Linked Custom Properties (97)

    Phil,

    I've added the save-document line to "your" macro on update fields (you can now claim to be a co-author: someone wrote the original, Gary supplied a line or two of code, and you edited the original - way to go <img src=/S/grin.gif border=0 alt=grin width=15 height=15> )

    I kind of figured that all stories included the header and footer but wasn't 100% sure. Thks for the clarification.

    Now here's something that I didn't think I'd ever be doing: telling someone about how the Lounge works:
    >a way to be notified whenever someone posts to a thread in which we have a post
    There is. You can add a thread to a watch list (the icon in the upper right corner that has a sheet of paper going into a folder with a plus sign). I tried it once. I assume it works even tho the thread I chose to watch had no more posts. I hope the theory is that I'd get an email with anything posting to that thread (kind of like getting a reply but w/o me sending something explicit for you to reply to).

    What I was aiming for was a way of doing a cc when making a post. When I replied to you earlier, I also replied directly to Gary and Stuart telling them to see my post to you. Unless they are watching everything, they may not see my reply to you. They certainly don't get a "reply to post" email.

    But you're right about having lots of features. Just need to know what they are and when to use them.

    As mentioned, I tried doing a few things with the File | Properties dialog - not just opening and closing. And got no VBA code beyond the shell.

    Fred

  12. #12
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Linked Custom Properties (97)

    Fred,

    I was just about to respond to your earlier post, when I saw this one.

    Stuart's macro only updates fields in the document's headers/footers (which may be all you need to do; depends on the situation). As far as testing whether or not the header/footer is linked, I don't know if that test is necessary (have never tested it either way), but it is a nice touch.

    There are 11 different types of storyranges listed in the VBA/Word object browser. Six of them pertain to headers/footers but there are others for the main text story, textframe (for text in shapes) - have a look at the whole list (I'm too lazy to type it!).

    "Userface": this is the result of trying to write something lucid at 2am!

    cc: alerts: Don't matter to me. I just go to the Lounge and check the forums I'm interested in.

    Regards,
    Gary

  13. #13
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Linked Custom Properties (97)

    Hi Fred:
    Thanks for the information on the watched thread. I actually knew about it, but have only used it for marking a thread I wanted to review more thoroughly. I just go to the bottom of the unread posts in Word & work my way to the top (hopefully).

  14. #14
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Linked Custom Properties (97)

    > I'm just curious as to why it matters, if you're updating all headers/footers for any fields, whether a
    > header/footer is linked to the previous

    It doesn't really, but the code I entered was cut down from a Macro that also adds stuff to the headers, without those checks the extra stuff would get added twice.

    Also the check is very cheap, updating fields in a long document can use significant resources - today I did an update fields on a 350 page document with about 4500 fields and it took over 5 minutes.

    StuartR

  15. #15
    Silver Lounger
    Join Date
    Jan 2001
    Location
    West Long Branch, New Jersey, USA
    Posts
    1,921
    Thanks
    6
    Thanked 9 Times in 7 Posts

    Re: Linked Custom Properties (97)

    Hi Stuart,

    Thks for the insights.

    Fred

Page 1 of 2 12 LastLast

Posting Permissions

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