From the course: Microsoft Office Add-Ins for Developers

Introduction to ScriptLab

From the course: Microsoft Office Add-Ins for Developers

Start my 1-month free trial

Introduction to ScriptLab

- [Instructor] A group within Microsoft have built a very useful tool for building and prototyping add-ins called Script Lab. Let's find it in the store. So if I go to the insert tab and My Add-ins, and go to the store, it's actually at the top of the list here, but it might not be in your case, and you might have to go searching for it. So I type in the search box Script Lab, and it's two words. If you write Script Lab all one word, it won't find it, and then that will find it, and we can add the add-in, and we'll get a new tab in the ribbon, and a little help message. So Script Lab is currently available for Excel, Word, and PowerPoint. At the time of the recording, it was not available for Outlook, but that could well change. We can go to the store and install it because as well as being a tool for building add-ins, it is itself, an add-in, a meta add-in, if you like. So let's see what happens when we run it. So I'm in a blank Excel document here, and I'm going to click on the Code button in the Script Lab ribbon tab. And you can see you get a nice editor which amongst other things, has a degree of InteliSense so we can get a lot of help as we're editing the script of whatever the add-in that we're building. So remember, this is an add-in, but it's a tool for building add-ins, and we've got another tab here which has got some markup, some HTML, a button or two in this case. You might have a little bit of style in there as well for CSS styling, and then there's another tab here that's got some references to various libraries that we're pulling in and using to help build the application, the add-in. And then over here, we can look at these very rich samples that we have for Excel, and I can scroll down here, and look for one here that's called Update Named Item. Let's look at this one. So that will load that sample in, and then again it loads its script, and we can see that in this case we've got a few buttons, and some script that's going to add some behavior when we click on the buttons. Good, let's see what happens when we run this add-in. So I'm going to click on the Run button in the ribbon now, and you see we now get a second add-in pane, and this is the actual add-in that we're running, so this on the left hand side is the code. That's the Script Lab add-in, and then the actual add-in that we've built is on the right hand side in this run pane, and let me make a bit more space here, and then we'll run that and add some sample data. So what this has done is add some content into the page, and we've got another button here that says add named item for range, so if I click on that I now get this region of cells is now a named range in Excel, and this one obviously isn't, but if I click on this second button here, it will move that named range of cells. You can see from the reference here in the name box that it's moved that range to the second group of cells. So we can look at the code behind this, and see what it's actually doing. So we've got two buttons for adding the named item and updating the named item which called these methods update named item and add named item, and then there's the set-up button. The ad sample data was calling this set-up method, and if we scroll down, we can see that the add named item uses the Excel Office API to set some properties on the sheet. It gets hold of the sheet, sets its range, and a similar sort of thing in the update named item, and then the set-up function down here is what's actually populating it with the initial data. And the interesting thing is, we can now edit this. So let's say we want to change the color of that range from yellow to blue. I can actually update the code, and straight away, if we look in the Run panel, it knows that we've made a change, and so it offers us the option to refresh it, so I can refresh the add-in, and now if I add sample data, you see it's now reflecting the changes we made to the code. So we've got a very easy and quick development cycle where we can quickly try out ideas and experiment with them.

Contents