View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tim Zych Tim Zych is offline
external usenet poster
 
Posts: 389
Default HOW CAN I WRITE A CODE TO COMMANDBUTTON ADDED AT RUNTIME?

You could theoretically write code to write code, but you will probably run
into problems quickly (virus detection may think it's a virus and
quarantines the workbook. The code persists, so it needs to be cleaned up
and rebuilt. The macro is reformed as a string, making edits a pain).

John Walkenbach has a nifty macro to do this using a class, avoiding the
problems above.

http://www.j-walk.com/ss/excel/tips/tip44.htm

To delve into this more, if you have access to it, check out Francesco
Balena's Programming Visual Basic 6. Balena's one of the best authors out
there and he has a chapter in his book devoted dynamically created forms and
events.


--
Tim Zych
www.higherdata.com
Compare data in worksheets and find differences with Workbook Compare
A free, powerful, flexible Excel utility


"Kozete" wrote in message
...
After I add a CommandButton control to a UserForm by Add method, how can I
write a code to that CommandButton?

--
Kozete