Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default add macro to wksht

Is there a programmatic way in VBA to add a simple macro (sub) to
workbook? i.e, a macro that inserts a macro.

The newly created sub can be contained in ThisWorkbook, the sheets, o
in a new Module.

My intention is that the macro would create a simple macro (for
button) that then resides within that workbook so as to allow macr
"portability", and is not limited to working only if the personal.xl
happens to have that macro

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default add macro to wksht

See Chip Pearson's
http://www.cpearson.com/excel/vbe.htm

Try this macro to create a button on Sheet1 and add code in the click event
in the sheet module.

Sub test()
Dim WS As Worksheet
Dim Btn As OLEObject
Set WS = ThisWorkbook.Worksheets("Sheet1")
With WS
Set Btn = .OLEObjects.Add(ClassType:="Forms.CommandButton.1" , _
Left:=.Range("C3").Left, Top:=.Range("C3").Top, _
Width:=100, Height:=30)
End With
Btn.Object.Caption = "Click Me"
Btn.Name = "TheButton"
With ThisWorkbook.VBProject.VBComponents(WS.CodeName).C odeModule
.InsertLines .CreateEventProc("Click", Btn.Name) + 1, _
"Msgbox ""Hi there"" "
End With
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"i-Zapp " wrote in message ...
Is there a programmatic way in VBA to add a simple macro (sub) to a
workbook? i.e, a macro that inserts a macro.

The newly created sub can be contained in ThisWorkbook, the sheets, or
in a new Module.

My intention is that the macro would create a simple macro (for a
button) that then resides within that workbook so as to allow macro
"portability", and is not limited to working only if the personal.xls
happens to have that macro.


---
Message posted from http://www.ExcelForum.com/



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
1st 2 rows of wksht show up @ top of each page of the wksht Remote Paralegal Excel Discussion (Misc queries) 2 October 6th 08 07:59 PM
Macro to Copy/Paste Data into one wksht, skipp one row before past Shoney Excel Discussion (Misc queries) 1 February 22nd 08 01:28 AM
Posting Data From 1 Wksht to Another RobL Excel Worksheet Functions 1 December 5th 07 07:50 PM
Adding a collection to a wksht CLamar Excel Discussion (Misc queries) 1 June 23rd 06 04:31 PM
Need macro to remove duplicate rows in a wksht with same order# G2 in AUS Excel Discussion (Misc queries) 2 December 16th 05 05:44 PM


All times are GMT +1. The time now is 11:39 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"