Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    St. George, Maine, USA
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA code for auto response to msg box request (Word 97)

    I don't do VBA except for adjusting a few recorded macros.
    One macro results in a system message box requiring a Yes or No response click.
    Could someone refresh my memory as to how to have 'No' automatically clicked.

    Thanks,
    Bob_D

  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: VBA code for auto response to msg box request (Word 97)

    One crude technique is SendKeys, but perhaps there is a parameter for the preceding command that could be tweaked. Which line is being executed when the dialog comes up?

  3. #3
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA code for auto response to msg box request (Word 97)

    Application.DisplayAlerts = wdAlertsNone

    The help for this carries the warning
    <hr>Note. If you set this property to wdAlertsNone or wdAlertsMessageBox, Word doesn't set it back to wdAlertsAll when your macro stops running. You should write your macro in such a way that it always sets the DisplayAlerts property back to wdAlertsAll when it stops running.<hr>
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  4. #4
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    St. George, Maine, USA
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA code for auto response to msg box request (Word 97)

    Geoff,
    The
    Application.DisplayAlerts = wdAlertsNone
    suppressed the message box prompt but it took the default response path, the Yes one. I need the No response path.

    The 'SendKeys' suggestion worked properly with
    SendKeys = "n"
    preceeding the function reference.

    Thanks to both of you for the prompt suggestions.

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Christchurch, New Zealand
    Posts
    250
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: VBA code for auto response to msg box request (Word 97)

    Here's one if you want to give the user the option of selecting Yes or No, but you want to make the default No.

    Sub MoreItems()
    Dim Response
    Dim ButtonStyle

    ButtonStyle = vbYesNo + vbCritical + vbDefaultButton2
    Response = MsgBox(Prompt:="Do you have more items for the statement?", _
    Buttons:=ButtonStyle, _
    Title:="Settlement Statement")

    If Response = vbYes Then
    'your code here

    ElseIf Response = vbNo Then
    'your code here
    End If
    End Sub

  6. #6
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA code for auto response to msg box request (Word 97)

    Karen,

    I suspect that the response is for a system generated message, not for a msgbox. It's good to know you can change a msgbox default button- it would be better to know how the change the default to "No"
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  7. #7
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA code for auto response to msg box request (Word 97)

    Bob,

    It's too late to solve your problem now.

    One way around might depend on what caused the message. For instance, if the message asks "do you want to save the document" on File Close, you can set "Activedocument.saved = true" (or ActiveDocument.Close savechanges:=False).

    It would be more "elegant" than sendkeys- which can occasionally be dangerous.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

Posting Permissions

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