Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Jan 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Modify Heading how? (XP)

    Hi,

    I have an application which contains 9 modify buttons, 1 for each Heading type 1-9. When clicked, the user is displayed the 'Modify Style' window for the Heading clicked. Here is the code:

    With Dialogs(wdDialogFormatStyle)
    Name = "Heading 2"
    Execute
    SendKeys ("%M")
    Show
    End With

    However, if the user changes the Heading name to a custom name, ie: 'My Heading 2', the code breaks.

    Is there any way to get around this?

    Thanks.

  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: Modify Heading how? (XP)

    You can display the dialog and interrogate the Styles collection before executing the user's action:
    <pre>Option Explicit
    Sub chrisf()
    Dim strStyName As String, lngAction As Long, objSty As Style
    strStyName = "Heading 2"
    With Dialogs(wdDialogFormatStyle)
    .Name = strStyName
    '.Execute
    SendKeys "%M"
    lngAction = .Display
    Set objSty = ActiveDocument.Styles(strStyName)
    If objSty Is Nothing Then
    MsgBox "You fool! You've messed up my macro by nuking " & strStyName
    'do something about it?
    Exit Sub
    ElseIf objSty.NameLocal <> strStyName Then
    MsgBox "You fool! You've messed up my macro by renaming " & strStyName
    'do something about it?
    Set objSty = Nothing
    Exit Sub
    Else
    If lngAction = -1 Then
    .Execute
    End If
    Set objSty = Nothing
    End If
    End With
    End Sub</pre>

    But do you really need to do this? How likely a problem is this?

Posting Permissions

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