Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42292

Excel-VBA Adding unknown amount of (dynamic) CommandBarControls

$
0
0
Hi

Im trying come up with a template that has several userforms(tools) that do certain things and i need a button to start each tool when its pressed.

now each tool will just consist of a userform, and all the code related to it will be kept inside the forms class (until i can decide whether or not its worth setting up sharing of code)
there will be some shared code which im putting inside a module to handle what data is passed to the form upon request eg. range etc..

i also want to include a shared module which handles adding button to the ribbon/commandbar but i cant seem to make it work

im familiar with adding buttons and ive done it a few times using vb.net and interop, but vba always stumps me.

so i think what i need is

create a control for each form in the project, its name is the name of the form, and a single click handler to handle them all based on a tag or name

im hoping something like this (psuedo)

Code:

for each userform in project
call MyAddNewControl(formname, msocommandbarbutton)
next

MyAddNewControl(Name as string, ControlType as msoControlType)
..........
'then the basic stuff, set var as new menucontrol etc
'onaction = "customcontrolclick"
end sub

i tried with an array but then found out i cant redim, :/
i tried just setting an array to a size and testing with 1 control, i cant get that to go through either

i keep getting object not set etc, usual error i get when using vba.

i was going to post what i had but i forgot to save it :/ but its basically adding 1 control to a custom menu and its showing in the addin tab on excel
ive got the cleanup as well before i create controls and also before the worksheet closes.

Viewing all articles
Browse latest Browse all 42292

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>