How to create a code of clicking the button in VBA?
up vote
0
down vote
favorite
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
add a comment |
up vote
0
down vote
favorite
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
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
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
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
excel vba excel-vba
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
add a comment |
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
add a comment |
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 MsgBox
is 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 MsgBox
will 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.
add a comment |
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 MsgBox
is 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 MsgBox
will 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.
add a comment |
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 MsgBox
is 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 MsgBox
will 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.
add a comment |
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 MsgBox
is 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 MsgBox
will 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.
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 MsgBox
is 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 MsgBox
will 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.
answered Nov 10 at 15:39
PGCodeRider
2,0031624
2,0031624
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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