Messagebox to run macro not working
Results 1 to 3 of 3

Thread: Messagebox to run macro not working

  1. #1
    New Member
    Join Date
    Jan 2018
    Posts
    4
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Messagebox to run macro not working

    I'm trying to use an Ok/Cancel Message box to run a macro, however, it's just not working

    If I use the below code regardless of if Ok or Cancel is pushed the macro will run
    Code:
    Sub Button()'
    ' Button Macro
    '
    Dim Answer As String
    
    
    MsgBox "WARNING: The following process will clear all of today's submitted trades! Do you wish to proceed?", vbOKCancel + vbQuestion
    
    
    Run "EODBACKUP"
    
    
    End Sub
    However, if I use the below regardless of if Ok or Cancel is pushed the macro doesn't run at all
    Code:
    Sub Button()'
    ' Button Macro
    '
    Dim Answer As String
    
    
    MsgBox "WARNING: The following process will clear all of today's submitted trades! Do you wish to proceed?", vbOKCancel + vbQuestion
    
    
    If ans = vbOK Then
    
    
    Run "EODBACKUP"
    
    
    End If
    
    
    End Sub
    Can someone please advise me what I'm doing wrong here?

    Thanks in advance

  2. #2
    Board Regular
    Join Date
    Apr 2019
    Posts
    72
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Messagebox to run macro not working

    You declared variable 'Answer' and later on you deal with 'ans'...

    Try like this:


    Code:
    Sub Button() '
    Dim answer As String
    answer = MsgBox("WARNING: The following process will clear all of today's submitted trades! Do you wish to proceed?", vbOKCancel + vbQuestion)
    If answer = vbOK Then
        MsgBox ("Macro will run.")
        'Call YOUR_MACRO
    End If
    End Sub

  3. #3
    New Member
    Join Date
    Jan 2018
    Posts
    4
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Messagebox to run macro not working

    That's brilliant Kokosek!
    Thanks so much.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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