Results 1 to 3 of 3
  1. #1
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    InsertCaption macro (Word2000 SR1a)

    I am trying to intercept Word's Insert Caption command.

    I have a created a macro called InsertCaption in a global template. This does intercept the command properly.

    Inside my Macro, I want to display the standard word Insert Caption dialog box and manipulate its controls before inserting the caption.

    I have tried using
    <pre>Dialogs(wdDialogInsertCaption).Display
    </pre>

    and then manipulating the "Title" before
    <pre>Dialogs(wdDialogInsertCaption).Execute
    </pre>

    but it appears that the .Display does exactly the same as .Show, inserting the caption in the document before returning to my code.

    Am I doing something wrong, or is .Display supposed to do this?

    StuartR

  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: InsertCaption macro (Word2000 SR1a)

    In theory, .Display captures the user's input so that you can manipulate it before you .Execute, whereas .Show simply does both in succession. In practice, however... the .Display method of this dialog does seem to prematurely execute on its own.

    I thought I had the system beat, but I still get an excess "Figure 1" in the document:

    <pre>Sub InsertCaption()
    With Dialogs(wdDialogInsertCaption)
    If .Display() Then
    ActiveDocument.Undo 'Remove first "Figure n"
    .Title = "This is a test!!"
    .Execute 'A second "Figure n" precedes the above title, for some reason
    End If
    End With
    End Sub</pre>

    The problem seems to be that the automatically generated Caption is not part of the .Title field. This other property also seems to be useless:

    .TitleAutoText = "Who am I?"

    And in fact I don't see how you can access the user's string until it is inserted into the document, as which time you could select it (for example, by using the Select method of a Range calculated from the before and after positions of the insertion point) and work with it in the document itself. Yuck.

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

    Re: InsertCaption macro (Word2000 SR1a)

    > you could select it (for example, by using the Select method of a Range calculated from the before
    > and after positions of the insertion point) and work with it in the document itself. Yuck.

    That's exactly what I ended up doing.

    The problem I am trying to solve is that multiple users are working on different chapters of a common document, they tend to insert different separators between the caption and their Title, some use " - ", others use Tab, one uses : and others use multiple spaces. I wanted to remove anything they inserted before the first alphanumeric and insert my own, standard, separator.

    I've done it now, but it ought to have been easier! In fact it ought to be something that Word does automatically, since the default behaviour of the title butting right up to the caption number is clearly absurd.

    StuartR

Posting Permissions

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