De: Iwer Mørck Objet: Sv: How to define an excel macro in VB? Date : jeudi 22 juillet 1999 23:34 Ollie (?) This is a copy of a reply to another user: I made a little example on how to create a button and assign code to it every time the macro is executed. to try it, create a new workbook, add a module, copy/paste this code into the module, run the first sub a couple of times (hit F5), switch to sheet1 and click the buttons. Here goes: Option Explicit Sub CreateButton() dim Sht1 As Worksheet dim n As long set Sht1 = worksheets(1) n = (Sht1.Buttons.count + 1) * 2 Sht1.Buttons.add Sht1.cells(n, 5).Left, _ Sht1.cells(n, 5).top, _ Sht1.cells(n, 5).width, _ Sht1.cells(n, 5).Height n = Sht1.Buttons.count Sht1.Buttons(n).name = n Sht1.Buttons(n).Caption = "Button " & n Sht1.Buttons(n).OnAction = "BtChange" set Sht1 = Nothing end Sub Sub BtChange() dim Sht1 As Worksheet dim cl As String set Sht1 = worksheets(1) cl = application.Caller msgbox "Button " & cl & " clicked. Now deleting it!" Sht1.Buttons(cl).delete set Sht1 = Nothing end Sub This might give you an idea. -- Cheers Iwer Moerck ----------------- iwer.moerck@get2net.dk ----------------- skrev i en nyhedsmeddelelse:7n6ht3$le5$1@nnrp1.deja.com... > I created an Excel file in VB with a button on a worksheet. I want to > assign an event to the button. How do I do this? > I expect with a macro, but how do I create an Excel Macro in VB? > > > Sent via Deja.com http://www.deja.com/ > Share what you know. Learn what you don't.