Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Tdp Tdp is offline
external usenet poster
 
Posts: 74
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,533
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.misc
CmK CmK is offline
external usenet poster
 
Posts: 69
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.misc
Tdp Tdp is offline
external usenet poster
 
Posts: 74
Default 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



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default 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
|
|




  #6   Report Post  
Posted to microsoft.public.excel.misc
Tdp Tdp is offline
external usenet poster
 
Posts: 74
Default 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
|
|



  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default 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


  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,344
Default 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

  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA code for macro help Cam Excel Discussion (Misc queries) 0 September 7th 07 07:14 PM
Deleting code from a macro (by a macro) Brettjg Excel Discussion (Misc queries) 2 May 8th 07 10:14 PM
Macro code Shu of AZ Excel Discussion (Misc queries) 2 January 29th 07 06:29 PM
Help With Macro Code?? Neil Smith Excel Worksheet Functions 1 August 24th 06 07:40 PM
Zip Code Macro Ken Wright Excel Worksheet Functions 0 December 9th 04 07:55 AM


All times are GMT +1. The time now is 12:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"