Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default Assigning procedures Programatically

I have the following code to copy one VBA command button to another location:

Me.cmdFilterRow19.Copy
Me.Paste Me.Cells(rngRow.Offset(-2, 0).Row,
Me.Range("FilterMatrix").Column + 3)

Me.OLEObjects("CommandButton1").Name = "cmdFilterRow" & rngRow.Offset(-2,
0).Row
---

Now I know I can access the command button as either an OLE object or an
MSforms.Commandbutton, but I can't find anyway to programmatically add
'_click' event code to the new button. Is this even possible, or am I stuck
using Excel Buttons for this situation? Thanks.



--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Assigning procedures Programatically

Check out Chip Pearson's site:
http://cpearson.com/excel/vbe.htm

Another option (that I think is easier)...

Use a button from the Forms toolbar. The assigned macro will travel with the
copy--or you could even assign a different macro after you do the paste.



J Streger wrote:

I have the following code to copy one VBA command button to another location:

Me.cmdFilterRow19.Copy
Me.Paste Me.Cells(rngRow.Offset(-2, 0).Row,
Me.Range("FilterMatrix").Column + 3)

Me.OLEObjects("CommandButton1").Name = "cmdFilterRow" & rngRow.Offset(-2,
0).Row
---

Now I know I can access the command button as either an OLE object or an
MSforms.Commandbutton, but I can't find anyway to programmatically add
'_click' event code to the new button. Is this even possible, or am I stuck
using Excel Buttons for this situation? Thanks.

--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default Assigning procedures Programatically

Yeah I know it is easier but there are graphic and interaction issues that
move me to do something a bit more complex. Thanks for th info though, looks
like just what I need.

--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003



"Dave Peterson" wrote:

Check out Chip Pearson's site:
http://cpearson.com/excel/vbe.htm

Another option (that I think is easier)...

Use a button from the Forms toolbar. The assigned macro will travel with the
copy--or you could even assign a different macro after you do the paste.



J Streger wrote:

I have the following code to copy one VBA command button to another location:

Me.cmdFilterRow19.Copy
Me.Paste Me.Cells(rngRow.Offset(-2, 0).Row,
Me.Range("FilterMatrix").Column + 3)

Me.OLEObjects("CommandButton1").Name = "cmdFilterRow" & rngRow.Offset(-2,
0).Row
---

Now I know I can access the command button as either an OLE object or an
MSforms.Commandbutton, but I can't find anyway to programmatically add
'_click' event code to the new button. Is this even possible, or am I stuck
using Excel Buttons for this situation? Thanks.

--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default Assigning procedures Programatically

Just tried the add event and it looks like it's really not possible to add a
VBA button to a sheet and add event handler code to it in the same procedure.
This creates the module to module interaction Chip warned about. Anyone get
around this issues, as it crashes Excel every time?

--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003



"Dave Peterson" wrote:

Check out Chip Pearson's site:
http://cpearson.com/excel/vbe.htm

Another option (that I think is easier)...

Use a button from the Forms toolbar. The assigned macro will travel with the
copy--or you could even assign a different macro after you do the paste.



J Streger wrote:

I have the following code to copy one VBA command button to another location:

Me.cmdFilterRow19.Copy
Me.Paste Me.Cells(rngRow.Offset(-2, 0).Row,
Me.Range("FilterMatrix").Column + 3)

Me.OLEObjects("CommandButton1").Name = "cmdFilterRow" & rngRow.Offset(-2,
0).Row
---

Now I know I can access the command button as either an OLE object or an
MSforms.Commandbutton, but I can't find anyway to programmatically add
'_click' event code to the new button. Is this even possible, or am I stuck
using Excel Buttons for this situation? Thanks.

--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Assigning procedures Programatically

This worked ok for me:

Option Explicit
Sub testme()

Dim OLEObj As OLEObject
Dim wks As Worksheet

Set wks = ActiveSheet

With wks
With .Range("a1:b2")
Set OLEObj = .Parent.OLEObjects.Add _
(ClassType:="Forms.CommandButton.1", _
Link:=False, DisplayAsIcon:=False, _
Left:=.Left, Top:=.Top, _
Width:=.Width, Height:=.Height)
End With

With .Parent.VBProject.VBComponents(.CodeName).CodeModu le
.InsertLines .CreateEventProc("Click", OLEObj.Name) + 1, _
"Msgbox ""Hi"""
End With
End With

End Sub




J Streger wrote:

Just tried the add event and it looks like it's really not possible to add a
VBA button to a sheet and add event handler code to it in the same procedure.
This creates the module to module interaction Chip warned about. Anyone get
around this issues, as it crashes Excel every time?

--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

"Dave Peterson" wrote:

Check out Chip Pearson's site:
http://cpearson.com/excel/vbe.htm

Another option (that I think is easier)...

Use a button from the Forms toolbar. The assigned macro will travel with the
copy--or you could even assign a different macro after you do the paste.



J Streger wrote:

I have the following code to copy one VBA command button to another location:

Me.cmdFilterRow19.Copy
Me.Paste Me.Cells(rngRow.Offset(-2, 0).Row,
Me.Range("FilterMatrix").Column + 3)

Me.OLEObjects("CommandButton1").Name = "cmdFilterRow" & rngRow.Offset(-2,
0).Row
---

Now I know I can access the command button as either an OLE object or an
MSforms.Commandbutton, but I can't find anyway to programmatically add
'_click' event code to the new button. Is this even possible, or am I stuck
using Excel Buttons for this situation? Thanks.

--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003


--

Dave Peterson


--

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
Checkbox procedures rbbbbeee Excel Programming 4 August 17th 06 03:43 PM
Get VBA procedures from DB Hiran de Silva[_2_] Excel Programming 3 July 4th 06 05:46 PM
Event Procedures in an Add-In DJB[_10_] Excel Programming 3 September 17th 05 08:11 AM
VBA Sub procedures lexiez Excel Programming 2 October 4th 04 04:21 PM
ListBox Procedures Rockee052[_48_] Excel Programming 1 February 20th 04 09:20 AM


All times are GMT +1. The time now is 05:31 AM.

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

About Us

"It's about Microsoft Excel"