Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    179
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hi all,

    I want to catch the opening of the Caption dlg box and then get the values of the dlg box's fields and then close the dlg box and write out the caption line the way *I* want to do it.

    So I read in the Help that if you open the dlg box using the Display method, then when you close the dlg box (even using OK) then the usual functionality of the dlg box is not executed. So I write the following test subroutine:

    Code:
    Sub InsertCaption()
    '
    ' InsertCaption Macro
    ' Inserts a caption above or below a selected object
    '
        Dim Ret As Integer
        
        Ret = Dialogs(wdDialogInsertCaption).Display
        
        Selection.Style = "Figure Caption"
      
    End Sub
    However, on emerging from the dlg box, I see that it nevertheless does get executed and writes its own caption line.

    Is there something I am doing wrong?

    Or have I simply misunderstood the concept of "without execution" where it is stated in the Help: "The Display method displays a dialog box without executing the actions taken in the dialog box."

    TIA

    - avraham

  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
    Display usually doesn't execute the dialog action automatically. However, this may be one of the few exceptions. Perhaps use Undo, as in this partially nonsensical demo code:

    Code:
    Sub TESTInsertCaption()
    With Dialogs(wdDialogInsertCaption)
        If .Display <> 0 Then
            ' Not canceled!
            ' Undo insertion of the caption
            ActiveDocument.Undo
            ' Capture parameters into a Split()-able string
            Dim strParams As String
            strParams = .Label & "|" & .TitleAutoText & "|" & .Title & "|" & .Delete & "|" & .Position & "|" & .AutoCaption & "|" & .ExcludeLabel
            ' Reposition insertion point and insert custom caption
            With Selection
                If Split(strParams, "|")(4) = wdCaptionPositionAbove Then
                    If Selection.Type > 1 Then
                        .Collapse wdCollapseStart
                        .TypeText "My Caption" & vbCrLf
                    Else
                        .TypeText "My Caption" & vbCrLf
                    End If
                Else
                    If Selection.Type > 1 Then
                        .Collapse wdCollapseEnd
                        .TypeText vbCrLf & "My Caption"
                    Else
                        .TypeText "My Caption"
                    End If
                End If
            End With
        End If
    End With
    End Sub

  3. #3
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    179
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Also I have found that I can't change the caption. Modifying none of these has the desired effect:

    Label, TitleAutoText, Title, AutoCaption,



    - avraham

  4. #4
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    179
    Thanks
    3
    Thanked 0 Times in 0 Posts
    "However, this may be one of the few exceptions. "

    Oh dear ... not again ...

    Thanks,

    avraham

  5. #5
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    This does appear to be one of the exceptions.

    However, if you capture the Ret value for the dialog, you can control whether a caption gets inserted, and add your own text to the caption:

    Code:
    Dim Ret As Integer
    
        Ret = Dialogs(wdDialogInsertCaption).Display
        
        If Ret = -1 Then 'user clicked OK
          Selection.TypeText " This is my own caption"
        End If
    Gary

Posting Permissions

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