VSTO - Customize / Design Excel Ribbon using XML & .NET - ID Card Make

VSTO - Customize / Design Excel Ribbon using XML & .NET - ID Card Make Hey guys welcome back to my channel if you're new here I'm lumpam I in the last episode we'll learn how to create custom ribbon for Excel using visual designer in this episode I'll be showing you in detail how to create a custom ribbon and also manipulate existing commands using XML if you followed our ribbon AK series for VBA is going to be pretty much the same or I would say even more simplified in VST o if you just need the ribbon with standard controls like buttons drop down edit box or label visual designer.

VSTO - Customize / Design Excel Ribbon using XML & .NET

Can take care of all this however if you want to repurpose building commands or define context menus or take care of the backstage you know like menu bars and so on you only the ribbon xmo so it's much more powerful and advanced as compared to the visual designer before we begin if you have any please do not forget to subscribe for latest updates and also to support my channel so here is what we did in our priority sewed first going to.

Decide in for a quick recap there is nothing we've done in that this is just supplying foam and then the user control and so mainly the focus was on the ribbon design so this is what we design in our prior video let me quickly load it up so it's much easier to refer to all these controls and then add elements and you know like design it's much more simpler to do in the visual designer but there are.

Certain things that cannot be done using this visual designer so XML part comes in again we've done this in VBA and if you haven't seen that it is very useful video series you should definitely check it out okay so this is a label that's automatically assigned with the user name and application user name and then the environ ID and then the you know like just label again the version and.

Then this is so the task pane source the wind foam this is example of combobox and a drop down and then whatever you selects printed out here and then this is edit box that automatically recalculates total for example and this is example of checkbox okay so we'll try to do this similar thing in the XML now you can straight away export this into ribbon and then start doing it here as well we'll put it in the.

Different projects so that it's easier to follow for now let me just export this example you'll see it's automatically generated so even though this has been generated at the moment you'll see these are the steps that we need to follow to be able to implement this if I load this up now it's gonna be still the same so here okay so it still.

Works everything the same okay now if you look here here's our XML that was exported this is the XML from this designer driven design this one and then this is where the code goes okay now expert instruction here we need to add this in the you know I add in or workbook load events or document and then that is how it's gonna take a field effect okay so what I'm gonna do now I'm.

Just gonna take a backup of this XML so that we can reuse this easily I'm gonna first close this solution I'll start a new project again we'll create a add-in let's call this add an eczema or something so if you do not follow the price you a video ID in the XO heading.

Okay so we'll use this one this template and this cold is Excel add-in and then xmo ribbon something like that and then I'm gonna place this in the YouTube directory and I'm gonna leave the framework as it is okay so again this is just a template it does not contain anything at the moment now I'm gonna go and add component so in.

Our last video we added this component now we'll add this ribbon XML I'll just leave the name as it is okay so this is the same one that was auto-generated earlier when we were doing this okay and then here is the XML okay it's just like some code our dear which were you can utilize now what it says here is copied the following this and paste it there we'll do that and then here all this are place where we are gonna put our callback this is where we will be.

Putting all our callbacks I'm just gonna leave this part as it is okay so first I'm gonna copy this go to this again if you're designing if your project is workbook level or document level you paste it here in that this workbook or this document so we are here now so I'm going to uncomment this okay so in the prior project if you want to use the XML then this is for your face and then automatically it will instead of picking up the visual designer or even that you've done is gonna pick up.

The XML from the XML file okay so if I load this up now we have not done any customization so we should not see any tab rather we will install the prior add-in uninstall sir so this is from the prior one I'm now gonna maybe just take a snippet so that we can easily refer to it I'm gonna uninstall this for now so this is a new add-on that we just created okay so now there is no ribbon now coming back here let's go and put in.

Posts Related:

    Start putting down okay so this is again - ID Card Make

    We've gone through this this is the code that's gonna run on load and then this is the namespace schema and okay we'll go one by one and then it should not be difficult my group okay there must be a group in my head instead let's just quickly load this again okay there is none just leave it let's copy this group first so see the.

    Tag ends here and it begins here okay and this one is ending here itself it starts and ends here so this is of no use for us maybe we'll just copy it from here you'll hear so if we load this up now it will show but it's gonna error let's call this XML this is the label for that new tab and then these are all the labels ctrl f5 to.

    Open without debugging so here's a ribbon and then all of them seems to be there it's gonna give an error because there's no callback okay so to dynamically let's first assign a label on load and then we can perhaps reuse the same code so that we don't have to rewrite everything so opening this we can reuse some of this instead of this static label 1 2 & 3 we'll assign this.

    Dynamically again this is case sensitive so get label this is for a callback or you can say for event get label okay so on get label we will assign the code that we want to run here okay so let's call this oh sorry get label I'll just put a name like this okay and going to ribbon here this is where all the callbacks so starts here.

    And then any ends here okay so we'll assign and all this needs to be public okay if you use remember well we're doing for VBA if we use this custom UI you can automatically generate the callback signatures like the syntax but here it's you have to do this okay the name is going to be this and well let's see this can be like a.

    Control variable control as this okay so in excel when we do VBA we just need to assign it like this but here we need to assign in full of syntax like this and then we can say this is equal to this right hello for now like this or we can just make this to function it will return the string and return hello irrespective of the control it will return hello now let's try it first so.

    If there is any error it will be highlighted here as well even in the XML so it's much better than the one that we used earlier signature mismatch okay just give me one second okay it's my but this supposed to be the control okay so hello hello hello so based on the control idea we can assign the label now for this we can use select keys and ID dis control workers at that point of.

    Time okay so case so the name here oops the name here is the label one so first one of the case is this case two and three K is else it will return nothing and let's get rid of this so in the label one we want to return hello and the username so we can reuse this code that we use in another one here return if this control ID on.

    Runtime when it's refreshing is label 1 then we want to return this ok and then if it is the second label we want to return this and then the version info here it's kind of you turn this ok so let's give it a shot so now here it returned dynamically okay and this so you can assign the labels using now we can go ahead wait the next.

    One again this is just loading um the components so this is actually fine you

    Can actually do it yourself or let me if there's anyone who didn't follow the prior series episode it's gonna make it small sort of put it to the center screen and then let's put a label let's call this when you form.

    And then we'll just edit a spine as well oh sit down control and I'll just leave name as it is again and this is gonna be our task being text or label okay and now this is for the went back to our XML let's close all this okay button is there let's code is show - pain and then so user form so this will be the name of the code that is gonna run and this is a label and then if you.

    Want to assign the image it's pretty much the same you can just follow the one that we did earlier in ribbon X okay for a callback we'll just reuse this code just use up for this I can say if this dot ID score the.

    Distant so based on the idea we can call the different codes or we can just create two codes that will be simpler now let's just copy the code again instead of rewriting everything I'm just gonna copy this to the top okay the font must be a bit smaller let me make it bigger and worse it does mean.

    Okay so this one then just put a different title okay let me just leave it as it is and let's do the same for the userform if you miss the priority so just watch for all this okay loading it up again okay there's three errors let's fix that first.

    Oh what is this looks like we're good but let me quickly check that missing case okay this is not required because this is a stop.

    I'm just need to import down okay let's load again okay this is des pain we just created and there's the wind foam okay so now let's take care of this dynamic drop downs so this we have done this label dynamically and then these are two buttons that launches the task pane and the userform in this group will take.

    Care of two examples one will be dynamic menu and then a 1 will be static drop-down okay let's call this drop-down and we've gone through this example in our ribbon ax series again there are old all this reserve resources are there anytime you don't find anything some of the links in the video description could be broken so you can directly search from here as well okay okay so how I got.

    Here is from this particular link and once you go here you'll see here is a sample for the drop-down similarly there will be sample for all of them now going back to our XML here for this drop-down I think we can use this for now we can just get rid of this line so these are item 1 2 3 and 4 let's put item let's say London let's call this as City.

    Something like this the label and the idea I'm just gonna put it same maybe in New York oops I just make it bigger okay this cannot be blank untidy and next is gonna be maybe deli and then we can't even have a button here if you want we'll just leave this as we would have passed.

    Like this okay and if you want action you can assign it here so maybe here on action let's call this location that will be the name of the code no let's take care of the callback as well I'm just gonna close this for now even this we don't need it at a moment okay so let's take care of this callback I believe this location one action is.

    Gonna call location code and here we can add couple of things more maybe like variable text as string and again this corvex technology can be cannot be modified it has to be exactly how it is already specified these are the only parameter stuck in going here and then maybe like index as integer okay so here we can return a message box mmm maybe just very relaxed and index.

    Okay let's give it a shot - bloom were to vote up okay so the city this is the button and then here's London the index is zero New York and put up this we didn't put a button for that so let's try it out quickly so again if you already familiar with this you can you know I fast forward this the.

    Dome so button here we use this so for this button as well we can do this thing for the level is this and then on action we can call this code okay so this is working so based on the selection of the user or element you can run specific code within the add-in to do certain tasks in the world current workbook for example or if maybe pulling.

    Something from based on these parameters or criterias you can pull in something from external you know like sources you know close this and now we will talk a little bit more on how to construct this dynamic menu no let's try it dynamic menu these are combo box but instead of that will try the dynamic menu so quickly going back to our ribbon acts episode for VBA just quickly give.

    You a demo so this is a dynamic menu that we constructed that is on runtime okay and if I go to code yeah this is the one that grunts this is basically all string as a demonstration so we can reuse the callback as well as this and the example is also here by the way in this in the same page okay dynamic menu and as you scroll down get.

    Contain this what we want to use and this is example line so going back here instead of this combo box we're gonna have dynamic menu get this content we'll just leave it as it is label is already there maybe I'll just leave this as it is okay you can assign more properties I can say set image you can assign the size normal large and all this and then.

    Let me go back here and copy this signature again remember this and this should be public and this let me just copy this and then we'll try to get something dynamic from the current sheet workbook don't know let's make just a function because we want to return something and this get content menu should be the name of the code we need to prefix this okay for now.

    I'm gonna leave this as it is and then we want to return oops máximo you first let's try this ctrl f5 so these are dynamic menu Colbeck signature mismatch okay let me reject this so looks like the signature is not same let me just leave it like this modem is ok we have assigned the image in the source here and this was done using our.

    Custom UI editor and we've already set image so if we want to use the custom image then that's we have to approach differently okay I don't think we need to even open that I can directly change this msl let me change all this graph let me change all this too quickly replace this similarly with this.

    This button ID as well need to be all unique what I was just gonna give an error let's try one more time okay so all these are said the smiley but you get an idea okay so now we can look through whatever you know like the current work will get us if there are more sheets it will list the the name of the sheets.

    Here okay let's try them let me go ahead and delete all of them all these lines to somewhere here will make this part will look through the sheets and then we'll assign a value here so let's start off for let's call this SH as Excel dot worksheet and this admins thought sorry let's start from Global's just let him that application.

    Dot worksheets and we'll bring him here like this so the button ID can be the sheet name so remember this single code which is here and also the label is well this I'm gonna leave this as it is and we can also put on action.

    Go here and on action so the order does not matter it's case sensitive they'll just remember done and let's call this dynamic item just gonna be the co double run will take care of the signature in a bit and then here we need to invalidate.

    The controls otherwise it's not gonna reverse this you know I'll just leave it as it is let's see if it is working first I'm gonna add multiple sheets one about the cast okay just give me a moment I think it's just here this is nothing return a string if this doesn't work we can try to make a variable.

    Killam is specifically super turn button and the syntax seems to be okay looks like some assembly is missing let's import some more will import office interlope and may be specific to X so let's say X R equal to Microsoft interlope and this is gonna be.

    Okay because it doesn't seem to understand at the moment let me start up again I'm not be using the error handlers now so we can directly okay it looks like it's working now um more sheets okay for life okay now upon selection we can activate the sheets as well maybe we can try with a new workbook so book to book one so here we have only one sheet okay.

    Button one is static okay so these are all dynamic for the inmate semi so you already know where to find it in the same link you'll find a table as well as a visual you know like many of which you can see gallery where you can choose the image okay so let's quickly take care of this on action dynamic I ten here whatever is chosen we can we'll try a different method here whatever control.

    Was selected this is basically going to return the name of the sheet and for the first button is gonna call here we don't have action buttons I'm not gonna do anything even if you're clicks on it call demo button no action and for this one's is gonna call this one and which is this so we'll try to use maybe we'll try with simpler words first Lobos if we don't want to select the.

    DISCLAIMER: In this description contains affiliate links, which means that if you click on one of the product links, I'll receive a small commission. This helps support the channel and allows us to continuetomake videos like this. All Content Responsibility lies with the Channel Producer. For Download, see The Author's channel. The content of this Post was transcribed from the Channel: https://www.youtube.com/watch?v=C-F_hLt-goA
Previous Post Next Post