Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Command button to run a macro

Hi, really stuck. Thought I had written the code correctly but when I click
on my command button to run my macro, it comes up with 'Object required'.
When I click on Tools and then Macros, my macro on there is called
Sheet1.RemoveThem

My code looks like this - where have I gone wrong?
Private Sub CommandButton1_Click()
On Error GoTo Err_Command1_Click

Dim stMacroName As String

stMacroName = "Sheet1.RemoveThem"
DoCmd.RunMacro stMacroName

Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click

End Sub

Thanks for any help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Command button to run a macro

Try changing

DoCmd.RunMacro stMacroName

to

Application.Run stMacroName

HTH,
Bernie
MS Excel MVP


"sparkes84" wrote in message
...
Hi, really stuck. Thought I had written the code correctly but when I click
on my command button to run my macro, it comes up with 'Object required'.
When I click on Tools and then Macros, my macro on there is called
Sheet1.RemoveThem

My code looks like this - where have I gone wrong?
Private Sub CommandButton1_Click()
On Error GoTo Err_Command1_Click

Dim stMacroName As String

stMacroName = "Sheet1.RemoveThem"
DoCmd.RunMacro stMacroName

Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click

End Sub

Thanks for any help



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Command button to run a macro

Is this code in the same worksheet module that owns the commandbutton (Sheet1)?

If yes, you could just call the macro directly:

Option Explicit
Private Sub CommandButton1_Click()
Call RemoveThem
End Sub
Sub RemoveThem()
MsgBox "hi"
End Sub

And if the removeme procedure is in a different worksheet module than the
commandbutton_click:


Behind the sheet with the commandbutton:
Option Explicit
Private Sub CommandButton1_Click()
Call Sheet1.RemoveThem
End Sub

Behind Sheet1:
Option Explicit
Sub RemoveThem()
MsgBox "hi"
End Sub

Application.run doesn't make a lot of sense here -- unless you're building the
name of the procedure or the procedure is hidden/private.




sparkes84 wrote:

Hi, really stuck. Thought I had written the code correctly but when I click
on my command button to run my macro, it comes up with 'Object required'.
When I click on Tools and then Macros, my macro on there is called
Sheet1.RemoveThem

My code looks like this - where have I gone wrong?
Private Sub CommandButton1_Click()
On Error GoTo Err_Command1_Click

Dim stMacroName As String

stMacroName = "Sheet1.RemoveThem"
DoCmd.RunMacro stMacroName

Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click

End Sub

Thanks for any help


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Command button to run a macro

Couple good tutorials he
http://www.anthony-vba.kefra.com/vba/vbabasic1.htm
http://www.mrexcel.com/tip068.shtml


Good luck,
Ryan---


"Dave Peterson" wrote:

Is this code in the same worksheet module that owns the commandbutton (Sheet1)?

If yes, you could just call the macro directly:

Option Explicit
Private Sub CommandButton1_Click()
Call RemoveThem
End Sub
Sub RemoveThem()
MsgBox "hi"
End Sub

And if the removeme procedure is in a different worksheet module than the
commandbutton_click:


Behind the sheet with the commandbutton:
Option Explicit
Private Sub CommandButton1_Click()
Call Sheet1.RemoveThem
End Sub

Behind Sheet1:
Option Explicit
Sub RemoveThem()
MsgBox "hi"
End Sub

Application.run doesn't make a lot of sense here -- unless you're building the
name of the procedure or the procedure is hidden/private.




sparkes84 wrote:

Hi, really stuck. Thought I had written the code correctly but when I click
on my command button to run my macro, it comes up with 'Object required'.
When I click on Tools and then Macros, my macro on there is called
Sheet1.RemoveThem

My code looks like this - where have I gone wrong?
Private Sub CommandButton1_Click()
On Error GoTo Err_Command1_Click

Dim stMacroName As String

stMacroName = "Sheet1.RemoveThem"
DoCmd.RunMacro stMacroName

Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click

End Sub

Thanks for any help


--

Dave Peterson

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
Command button macro Mark N Excel Discussion (Misc queries) 6 August 28th 09 10:31 PM
Command button to run a macro CY Excel Programming 1 January 6th 07 06:13 AM
Command Button & Macro Tom Excel Programming 2 November 3rd 06 04:53 PM
Macro/Command Button Howard Excel Programming 7 August 21st 04 12:08 AM
Command Button & Macro alexm999[_10_] Excel Programming 2 January 28th 04 09:12 PM


All times are GMT +1. The time now is 07:53 AM.

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"