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

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » VBA code for auto response to msg box request (Word 97)

    Author
    Topic
    #357764

    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

    Viewing 2 reply threads
    Author
    Replies
    • #532182

      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?

    • #532183

      Application.DisplayAlerts = wdAlertsNone

      The help for this carries the warning[indent]


      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.


      [/indent]

      • #532235

        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.

        • #532303

          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.

    • #532301

      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

      • #532302

        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”

    Viewing 2 reply threads
    Reply To: VBA code for auto response to msg box request (Word 97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: