PDA

View Full Version : Create a Macro to add to an existing Macro



sswcharlie
06-07-2011, 11:25 PM
Hi

See also the 'Floating Toolbar' thread on this list.

Is it possible to have a macro to insert into a existing macro some more code.

That is in my case to add a new macro to be added to the floating toolbar.
It would need a userform to enter 2 or 3 details and then insert to the existing code.

Regards from NZ

Charlie

Jan Karel Pieterse
06-08-2011, 12:32 AM
You can, but it is unlikely that that is the best way to do this.
Can you give a bit more background?

sswcharlie
06-08-2011, 12:44 AM
Hi Jan
On VBAX forum http://www.vbaexpress.com/forum/showthread.php?t=37722
There is a WB (attachment)with macro to create a toolbar for two macros, and I would like to over time to add further macros onto the toolbar. So I thought instead of having to go into vbe each time there could be a macro to do the job. I guess any procedure would be ok.

Thanks

Charlie

Jan Karel Pieterse
06-08-2011, 02:13 AM
Well, you would have written the macro you want to add to the toolbar anyway, so adding the two or three lines of code to add the button to the toolbar should be quite simple, shouldn't it?

sswcharlie
06-08-2011, 01:54 PM
Hi Jan

I would like to have all the code in the same macro (add to existing code) but I am still not sure how you insert more code into an existing code except by manually doing it in VBE. Is there a vba code that selects the vbe, the specific macro, andthen I can insert whatever code I need.

Thanks

Charlie

frank_m
06-08-2011, 05:45 PM
Hi sswcharlie,

What Jan described to you is that yes it is possible, but not simply, and VERY likely not the best solution. - It's really best that you post a sample workbook with examples and explain the reasons for adding more to the code in certain situations. - For example, perhaps your situation may be handled with If Then Statements to test for varying circumstances or criteria.