Results 1 to 4 of 4

Thread: Which Stories?

  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Which Stories?

    I could not find a .Name property in the Word StoryRanges object (collection), so I wrote this tedious sub to tell me which StoryRanges are active in the activedocument. Just thought it might me helpful for someone else.

    <pre>Sub WhichStories()
    Dim aField As Field
    Dim aStory As Range

    On Error Resume Next
    For Each aStory In ActiveDocument.StoryRanges
    Select Case aStory.StoryType
    Case wdCommentsStory
    Debug.Print "Comment Story, Type: " & aStory.StoryType
    Case wdEndnotesStory
    Debug.Print "Endnotes Story, Type: " & aStory.StoryType
    Case wdEvenPagesFooterStory
    Debug.Print "EvenPagesFooter Story, Type: " & aStory.StoryType
    Case wdEvenPagesHeaderStory
    Debug.Print "EvenPagesHeader Story, Type: " & aStory.StoryType
    Case wdFirstPageFooterStory
    Debug.Print "FirstPageFooter Story, Type: " & aStory.StoryType
    Case wdFirstPageHeaderStory
    Debug.Print "FirstPageHeader Story, Type: " & aStory.StoryType
    Case wdFootnotesStory
    Debug.Print "Footnotes Story, Type: " & aStory.StoryType
    Case wdMainTextStory
    Debug.Print "Main Text Story, Type: " & aStory.StoryType
    Case wdPrimaryFooterStory
    Debug.Print "Primary Footer Story, Type: " & aStory.StoryType
    Case wdPrimaryHeaderStory
    Debug.Print "Primary Header Story, Type: " & aStory.StoryType
    Case wdTextFrameStory
    Debug.Print "TextFrame Story, Type: " & aStory.StoryType
    End Select
    Next aStory

    End Sub
    </pre>

    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

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

    Re: Which Stories?

    Kevin,

    Thanks for sharing - this works well and is interesting to play around with.
    Was there a 'real-world' scenario that prompted you to create this? (I'm guessing if so, it has something to do with fields, considering the "Dim aField As Field" declaration <img src=/S/grin.gif border=0 alt=grin width=15 height=15>). Are there situations where you need to address each existing Story type specifically, as opposed to looping through them via For Each aStory in doc.StoryRanges?

    A really finicky point: would it be worth the trouble of re-ordering the case statements, to run from most commonly found to least - since (if what I read in this forum is accurate) the Select Case structure ends as soon as it finds a 'hit'?

    Gary

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Which Stories?

    Gary,

    Yes, a real-world situation prompted me to write this. When a user creates a document, the template may contain document variable references, but not the actual document variable. These show up in the document as "Error! bla bla bla" -- a very ugly situation and one I could not believe when I first saw them. I mean, so what if a reference does not have a corresponding value (or "result" to use MS terminology). Also, date fields need to be updated and the routine that checks for these "Error!" results also updates the date fields.

    As you know, using activedocument.fields.update only updates the fields in the MainStory, so in order to get a whack at all the fields, I step through each Story removing the "bad" fields and updating the date fields.

    I had an error in my logic that caused this funny message:

    Word cannot Undo this action. Do you want to continue?

    That was rather bizarre considering the On error resume next statement just above the offending line. Anyway, by displaying the current story name I found the bug.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Which Stories?

    Hi Kevin

    Interesting.

    I've starting getting the same message (using Word 2000, XP home edition), but I don't think it's macro-related. It happens with Ctrl+S, for example, and if I go Shift+F1 then Ctrl+S, it gives me the help message about FileSave (which I think proves that it's not a macro running).

    Curiously, it doesn't seem to always happen. Could it be a resource problem?

    Also, whichever button I click in the dialog box, I get moved to a different unrelated part of the document (the same place each time).

    Any ideas?
    (Maybe I should post this in the Word forum?)

    =====================================
    Since writing this, I've had two documents opened at the same time, and one misbehaves on Ctrl+S but the other doesn't. Corrupt document?
    =====================================

    -----------------------------------------------------------------
    And another update. I had a hyperlink to a URL in a footnote. Remove the hyperlink and the problem disappears. Insert it again, and it reappears. Grrrr.
    -----------------------------------------------------------------

    Dale

Posting Permissions

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