How to create a code of clicking the button in VBA?











up vote
0
down vote

favorite
1












I have created a messagebox and coded so that the excel goes to the specific range where the button exists. But I do not know how to code so that the macro automatically clicks the button.



Sub Start()
Range("A4").Select

< >
End Sub


Sub MessageBox()

MsgBox "Hi" & vbCrLf & "Professor", _
vbInformation, "Greetings"

End Sub


I need something < > in this space but the process to automatically get linked.



Anyone have an idea?










share|improve this question




















  • 1




    Unclear what you are asking
    – Andreas
    Nov 10 at 10:22






  • 2




    If you want to run the code which belongs to the button you just have to call it. There is no need to click on the button. Look at this
    – Storax
    Nov 10 at 10:25















up vote
0
down vote

favorite
1












I have created a messagebox and coded so that the excel goes to the specific range where the button exists. But I do not know how to code so that the macro automatically clicks the button.



Sub Start()
Range("A4").Select

< >
End Sub


Sub MessageBox()

MsgBox "Hi" & vbCrLf & "Professor", _
vbInformation, "Greetings"

End Sub


I need something < > in this space but the process to automatically get linked.



Anyone have an idea?










share|improve this question




















  • 1




    Unclear what you are asking
    – Andreas
    Nov 10 at 10:22






  • 2




    If you want to run the code which belongs to the button you just have to call it. There is no need to click on the button. Look at this
    – Storax
    Nov 10 at 10:25













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





I have created a messagebox and coded so that the excel goes to the specific range where the button exists. But I do not know how to code so that the macro automatically clicks the button.



Sub Start()
Range("A4").Select

< >
End Sub


Sub MessageBox()

MsgBox "Hi" & vbCrLf & "Professor", _
vbInformation, "Greetings"

End Sub


I need something < > in this space but the process to automatically get linked.



Anyone have an idea?










share|improve this question















I have created a messagebox and coded so that the excel goes to the specific range where the button exists. But I do not know how to code so that the macro automatically clicks the button.



Sub Start()
Range("A4").Select

< >
End Sub


Sub MessageBox()

MsgBox "Hi" & vbCrLf & "Professor", _
vbInformation, "Greetings"

End Sub


I need something < > in this space but the process to automatically get linked.



Anyone have an idea?







excel vba excel-vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 7:07









Pᴇʜ

18.6k42549




18.6k42549










asked Nov 10 at 10:16









Im Hun Jung

74




74








  • 1




    Unclear what you are asking
    – Andreas
    Nov 10 at 10:22






  • 2




    If you want to run the code which belongs to the button you just have to call it. There is no need to click on the button. Look at this
    – Storax
    Nov 10 at 10:25














  • 1




    Unclear what you are asking
    – Andreas
    Nov 10 at 10:22






  • 2




    If you want to run the code which belongs to the button you just have to call it. There is no need to click on the button. Look at this
    – Storax
    Nov 10 at 10:25








1




1




Unclear what you are asking
– Andreas
Nov 10 at 10:22




Unclear what you are asking
– Andreas
Nov 10 at 10:22




2




2




If you want to run the code which belongs to the button you just have to call it. There is no need to click on the button. Look at this
– Storax
Nov 10 at 10:25




If you want to run the code which belongs to the button you just have to call it. There is no need to click on the button. Look at this
– Storax
Nov 10 at 10:25












1 Answer
1






active

oldest

votes

















up vote
1
down vote













In your example it looks like you have the name of the macro, and if that's the case it should be easy to just call it. See below



Sub Start()
Range("A4").Select

Call MessageBox
End Sub

Sub MessageBox()

MsgBox "Hi" & vbCrLf & "Professor", vbInformation, "Greetings"

End Sub


However, I'm guessing that doesn't help you because what you're asking doesn't truly make sense. I'm going to guess that maybe by MsgBox, you actually mean Form or Command Button. These look similar but they are distinctly different.



A MsgBoxis more of an alert to the user with the option to capture a small amount of information back (i.e. yes/no/ok/cancel etc). Clicking on a MsgBoxwill never directly launch another macro. An ANSWER to a MsgBox(i.e yes/no) MIGHT determine if another Macro is run based on an if-statement, or if the next line of code is simply just to execute another macro.



If you have a macro running distinctly based on a click, the button is likely a Form or an active X command Button. You need to figure out what macro this object is executing and then you just need to include this in your code. Google "how to see what macro a form button runs in VBA" or if it's an active X button, right click on it and hit "View Code". Both of these approaches should drive you to a macro name such as CommandButton1_Click.



Unfortunately, you might have to get more fancy as if it's a sheet Commandbutton1_Click you may have to make it public. Hopefully you can insert a call that code in your current macro.



Hope that helps.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237947%2fhow-to-create-a-code-of-clicking-the-button-in-vba%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    In your example it looks like you have the name of the macro, and if that's the case it should be easy to just call it. See below



    Sub Start()
    Range("A4").Select

    Call MessageBox
    End Sub

    Sub MessageBox()

    MsgBox "Hi" & vbCrLf & "Professor", vbInformation, "Greetings"

    End Sub


    However, I'm guessing that doesn't help you because what you're asking doesn't truly make sense. I'm going to guess that maybe by MsgBox, you actually mean Form or Command Button. These look similar but they are distinctly different.



    A MsgBoxis more of an alert to the user with the option to capture a small amount of information back (i.e. yes/no/ok/cancel etc). Clicking on a MsgBoxwill never directly launch another macro. An ANSWER to a MsgBox(i.e yes/no) MIGHT determine if another Macro is run based on an if-statement, or if the next line of code is simply just to execute another macro.



    If you have a macro running distinctly based on a click, the button is likely a Form or an active X command Button. You need to figure out what macro this object is executing and then you just need to include this in your code. Google "how to see what macro a form button runs in VBA" or if it's an active X button, right click on it and hit "View Code". Both of these approaches should drive you to a macro name such as CommandButton1_Click.



    Unfortunately, you might have to get more fancy as if it's a sheet Commandbutton1_Click you may have to make it public. Hopefully you can insert a call that code in your current macro.



    Hope that helps.






    share|improve this answer

























      up vote
      1
      down vote













      In your example it looks like you have the name of the macro, and if that's the case it should be easy to just call it. See below



      Sub Start()
      Range("A4").Select

      Call MessageBox
      End Sub

      Sub MessageBox()

      MsgBox "Hi" & vbCrLf & "Professor", vbInformation, "Greetings"

      End Sub


      However, I'm guessing that doesn't help you because what you're asking doesn't truly make sense. I'm going to guess that maybe by MsgBox, you actually mean Form or Command Button. These look similar but they are distinctly different.



      A MsgBoxis more of an alert to the user with the option to capture a small amount of information back (i.e. yes/no/ok/cancel etc). Clicking on a MsgBoxwill never directly launch another macro. An ANSWER to a MsgBox(i.e yes/no) MIGHT determine if another Macro is run based on an if-statement, or if the next line of code is simply just to execute another macro.



      If you have a macro running distinctly based on a click, the button is likely a Form or an active X command Button. You need to figure out what macro this object is executing and then you just need to include this in your code. Google "how to see what macro a form button runs in VBA" or if it's an active X button, right click on it and hit "View Code". Both of these approaches should drive you to a macro name such as CommandButton1_Click.



      Unfortunately, you might have to get more fancy as if it's a sheet Commandbutton1_Click you may have to make it public. Hopefully you can insert a call that code in your current macro.



      Hope that helps.






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        In your example it looks like you have the name of the macro, and if that's the case it should be easy to just call it. See below



        Sub Start()
        Range("A4").Select

        Call MessageBox
        End Sub

        Sub MessageBox()

        MsgBox "Hi" & vbCrLf & "Professor", vbInformation, "Greetings"

        End Sub


        However, I'm guessing that doesn't help you because what you're asking doesn't truly make sense. I'm going to guess that maybe by MsgBox, you actually mean Form or Command Button. These look similar but they are distinctly different.



        A MsgBoxis more of an alert to the user with the option to capture a small amount of information back (i.e. yes/no/ok/cancel etc). Clicking on a MsgBoxwill never directly launch another macro. An ANSWER to a MsgBox(i.e yes/no) MIGHT determine if another Macro is run based on an if-statement, or if the next line of code is simply just to execute another macro.



        If you have a macro running distinctly based on a click, the button is likely a Form or an active X command Button. You need to figure out what macro this object is executing and then you just need to include this in your code. Google "how to see what macro a form button runs in VBA" or if it's an active X button, right click on it and hit "View Code". Both of these approaches should drive you to a macro name such as CommandButton1_Click.



        Unfortunately, you might have to get more fancy as if it's a sheet Commandbutton1_Click you may have to make it public. Hopefully you can insert a call that code in your current macro.



        Hope that helps.






        share|improve this answer












        In your example it looks like you have the name of the macro, and if that's the case it should be easy to just call it. See below



        Sub Start()
        Range("A4").Select

        Call MessageBox
        End Sub

        Sub MessageBox()

        MsgBox "Hi" & vbCrLf & "Professor", vbInformation, "Greetings"

        End Sub


        However, I'm guessing that doesn't help you because what you're asking doesn't truly make sense. I'm going to guess that maybe by MsgBox, you actually mean Form or Command Button. These look similar but they are distinctly different.



        A MsgBoxis more of an alert to the user with the option to capture a small amount of information back (i.e. yes/no/ok/cancel etc). Clicking on a MsgBoxwill never directly launch another macro. An ANSWER to a MsgBox(i.e yes/no) MIGHT determine if another Macro is run based on an if-statement, or if the next line of code is simply just to execute another macro.



        If you have a macro running distinctly based on a click, the button is likely a Form or an active X command Button. You need to figure out what macro this object is executing and then you just need to include this in your code. Google "how to see what macro a form button runs in VBA" or if it's an active X button, right click on it and hit "View Code". Both of these approaches should drive you to a macro name such as CommandButton1_Click.



        Unfortunately, you might have to get more fancy as if it's a sheet Commandbutton1_Click you may have to make it public. Hopefully you can insert a call that code in your current macro.



        Hope that helps.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 15:39









        PGCodeRider

        2,0031624




        2,0031624






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237947%2fhow-to-create-a-code-of-clicking-the-button-in-vba%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Full-time equivalent

            Bicuculline

            さくらももこ