ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   VB code to run macro? (https://www.excelbanter.com/excel-discussion-misc-queries/208689-vbulletin-code-run-macro.html)

Tdp

VB code to run macro?
 
I have a userform with a commandbutton1.
I have recorded a macro which I would to run it when commandbutton1 is
pressed.
--
Tdp

Per Jessen

VB code to run macro?
 
Hi

Copy the desired code without Sub... / End Sub statements.

Select your userform in the VBA editor and right click on commandButton1,
select "view code". The code window for your userform will show:

Private Sub CommandButton1_Click()

End Sub

Paste your code between theese two lines.

Regards,
Per


"Tdp" skrev i meddelelsen
...
I have a userform with a commandbutton1.
I have recorded a macro which I would to run it when commandbutton1 is
pressed.
--
Tdp



CmK

VB code to run macro?
 

Double click on the button and copy the recorded macro into it

Cheers



"Tdp" wrote:

I have a userform with a commandbutton1.
I have recorded a macro which I would to run it when commandbutton1 is
pressed.
--
Tdp


Tdp

VB code to run macro?
 
Sorry guys,
Its the other way round I'm after.
I have the code in the userform but I wish to move the code to a module,
name it macro1 and then in the userform code under commandbutton1 I want to
write a code to run macro1.
--
Tdp


"Per Jessen" wrote:

Hi

Copy the desired code without Sub... / End Sub statements.

Select your userform in the VBA editor and right click on commandButton1,
select "view code". The code window for your userform will show:

Private Sub CommandButton1_Click()

End Sub

Paste your code between theese two lines.

Regards,
Per


"Tdp" skrev i meddelelsen
...
I have a userform with a commandbutton1.
I have recorded a macro which I would to run it when commandbutton1 is
pressed.
--
Tdp




Andrew[_8_]

VB code to run macro?
 
Make sure Sub in Userform is not private..

Userform.UserformProcedurename
i.e.
In Sheet Code..
Sub CommandButton1_Click()
MyForm.FormCommandButton1_Click
End Sub

in Myform...
Sub FormCommandButton1_Click
' Do stuff...
End Sub

Hope Its of use..
A

"Tdp" wrote in message
...
| Sorry guys,
| Its the other way round I'm after.
| I have the code in the userform but I wish to move the
code to a module,
| name it macro1 and then in the userform code under
commandbutton1 I want to
| write a code to run macro1.
| --
| Tdp
|
|
| "Per Jessen" wrote:
|
| Hi
|
| Copy the desired code without Sub... / End Sub
statements.
|
| Select your userform in the VBA editor and right click
on commandButton1,
| select "view code". The code window for your userform
will show:
|
| Private Sub CommandButton1_Click()
|
| End Sub
|
| Paste your code between theese two lines.
|
| Regards,
| Per
|
|
| "Tdp" skrev i
meddelelsen
|
...
| I have a userform with a commandbutton1.
| I have recorded a macro which I would to run it when
commandbutton1 is
| pressed.
| --
| Tdp
|
|



Tdp

VB code to run macro?
 
Hi Andrew,
is the second code to be placed in a module?
--
Tdp


"Andrew" wrote:

Make sure Sub in Userform is not private..

Userform.UserformProcedurename
i.e.
In Sheet Code..
Sub CommandButton1_Click()
MyForm.FormCommandButton1_Click
End Sub

in Myform...
Sub FormCommandButton1_Click
' Do stuff...
End Sub

Hope Its of use..
A

"Tdp" wrote in message
...
| Sorry guys,
| Its the other way round I'm after.
| I have the code in the userform but I wish to move the
code to a module,
| name it macro1 and then in the userform code under
commandbutton1 I want to
| write a code to run macro1.
| --
| Tdp
|
|
| "Per Jessen" wrote:
|
| Hi
|
| Copy the desired code without Sub... / End Sub
statements.
|
| Select your userform in the VBA editor and right click
on commandButton1,
| select "view code". The code window for your userform
will show:
|
| Private Sub CommandButton1_Click()
|
| End Sub
|
| Paste your code between theese two lines.
|
| Regards,
| Per
|
|
| "Tdp" skrev i
meddelelsen
|
...
| I have a userform with a commandbutton1.
| I have recorded a macro which I would to run it when
commandbutton1 is
| pressed.
| --
| Tdp
|
|




Andrew[_8_]

VB code to run macro?
 
If you open the Form in VB Editor,
Right click - And... View Code - Put code in there..

Can be accessed from a module or from the Sheets' Code by
Prefixing
with the form name.

If you use the project explorer Sub window in Vb Editor-
(Ctrl+R) or View..Project Explorer
you will see your project and all parts of it (Workbook,
Worksheets , Forms and Modules).

In VB Editor - I Personally use this docked on the Left, and
the properties window Docked on the right.
Don't hesitate to ask if you need anymore help.
A.


"Tdp" wrote in message
...
| Hi Andrew,
| is the second code to be placed in a module?
| --
| Tdp
|
|
| "Andrew" wrote:
|
| Make sure Sub in Userform is not private..
|
| Userform.UserformProcedurename
| i.e.
| In Sheet Code..
| Sub CommandButton1_Click()
| MyForm.FormCommandButton1_Click
| End Sub
|
| in Myform...
| Sub FormCommandButton1_Click
| ' Do stuff...
| End Sub
|
| Hope Its of use..
| A



ShaneDevenshire

VB code to run macro?
 
Hi,

If the sub routine MyMacro is in a regular module and is not Private, that
means its name is

Sub MyMacro()

not

Private Sub MyMacro()

Then the code attached to CommandButton1 in your user form is simpy

Private Sub CommandButton1_Click()
myMacro
End Sub


--
Thanks,
Shane Devenshire


"Tdp" wrote:

I have a userform with a commandbutton1.
I have recorded a macro which I would to run it when commandbutton1 is
pressed.
--
Tdp


Andrew[_8_]

VB code to run macro?
 
Is that not what i said..? In previous - Sun 02 November
2008 13:00pm
A.

"ShaneDevenshire"
wrote in message
...
| Hi,
|
| If the sub routine MyMacro is in a regular module and is
not Private, that
| means its name is
|
| Sub MyMacro()
|
| not
|
| Private Sub MyMacro()
|
| Then the code attached to CommandButton1 in your user form
is simpy
|
| Private Sub CommandButton1_Click()
| myMacro
| End Sub
|
|
| --
| Thanks,
| Shane Devenshire
|
|
| "Tdp" wrote:
|
| I have a userform with a commandbutton1.
| I have recorded a macro which I would to run it when
commandbutton1 is
| pressed.
| --
| Tdp




All times are GMT +1. The time now is 12:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com