+ Reply to Thread
Results 1 to 7 of 7

Confirmation box

  1. #1
    Registered User
    Join Date
    08-14-2006
    Posts
    32

    Confirmation box

    I have writen a macro, but was just wondering if it is possible to add a confirmation box to popup at the start incase someone presses the button by mistake.

  2. #2
    Registered User
    Join Date
    12-15-2004
    Posts
    64
    Here is my Before Print sub which uses a Message Box to make sure that the user has updated the weekly data before they print the report not sure what your macro is doing but by changing the workbook event of adapting the code it should be what you need or at least a step in the right direction

    Private Sub Workbook_BeforePrint(Cancel As Boolean)

    Dim wk As Worksheet
    Dim Config As Integer
    Dim Ans As Integer

    For Each wk In Worksheets
    wk.Calculate
    Next

    Config = vbYesNo + vbQuestion + vbDefaultButton1
    Ans = MsgBox("Have you updated the weekly data?", Config, "Ensure correct data")

    If Ans = vbNo Then Cancel = True

    If Ans = vbYes Then Cancel = False

    End Sub

    Regards

    Adrian

  3. #3
    Ken Johnson
    Guest

    Re: Confirmation box


    Hi Alex,

    This is one way...

    Public Sub MyMacro()
    Dim Check As VbMsgBoxResult
    Check = MsgBox("Are you sure you want this macro to run?", vbYesNo)
    If Check = vbYes Then
    'Code Here
    End If
    End Sub

    Just make sure there is no code between End If and End Sub.

    Ken Johnson


  4. #4
    Registered User
    Join Date
    08-14-2006
    Posts
    32
    Where in my macro would i include this code?

  5. #5
    Ken Johnson
    Guest

    Re: Confirmation box

    Hi Alex,

    Dim Check As VbMsgBoxResult
    Check = MsgBox("Are you sure you want this macro to run?", vbYesNo)
    If Check = vbYes Then

    could be at the start of your code, then straight after the last line
    of your code (but before the End Sub line) the "End If" line.

    This way, your code is only run if the user clicks the "Yes" button.
    When the "No" button is clicked the code jumps to the "End If" then the
    End Sub, so nothing happens.

    Ken Johnson


  6. #6
    Registered User
    Join Date
    08-14-2006
    Posts
    32
    Thanks, i managed to work it out. This is the first time i've really tried to use macros for anything.

  7. #7
    Ken Johnson
    Guest

    Re: Confirmation box


    You're welcome Alex.
    Good Luck.

    Ken Johnson


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1