Microsoft 365 Roadmap Get the Latest Updates. Microsoft 365 is a complete, intelligent solution, including Office 365, Windows 10, and Enterprise Mobility + Security, that empowers everyone to be creative and work together, securely.
An Excel add-in allows you to extend Excel application functionality across multiple platforms including Windows, Mac, iPad, and in a browser. Use Excel add-ins within a workbook to:
Interact with Excel objects, read and write Excel data.
Extend functionality using web based task pane or content pane
Add custom ribbon buttons or contextual menu items
Add custom functions
Provide richer interaction using dialog window
The Office Add-ins platform provides the framework and Office.js JavaScript APIs that enable you to create and run Excel add-ins. By using the Office Add-ins platform to create your Excel add-in, you'll get the following benefits:
Cross-platform support: Excel add-ins run in Office on the web, Windows, Mac, and iPad.
Centralized deployment: Admins can quickly and easily deploy Excel add-ins to users throughout an organization.
Use of standard web technology: Create your Excel add-in using familiar web technologies such as HTML, CSS, and JavaScript.
Distribution via AppSource: Share your Excel add-in with a broad audience by publishing it to AppSource.
Note
Excel add-ins are different from COM and VSTO add-ins, which are earlier Office integration solutions that run only in Office on Windows. Unlike COM add-ins, Excel add-ins do not require you to install any code on a user's device, or within Excel.
Components of an Excel add-in
An Excel add-in includes two basic components: a web application and a configuration file, called a manifest file.
The web application uses the JavaScript API for Office to interact with objects in Excel, and can also facilitate interaction with online resources. For example, an add-in can perform any of the following tasks:
Create, read, update, and delete data in the workbook (worksheets, ranges, tables, charts, named items, and more).
Perform user authorization with an online service by using the standard OAuth 2.0 flow.
Issue API requests to Microsoft Graph or any other API.
The web application can be hosted on any web server, and can be built using client-side frameworks (such as Angular, React, jQuery) or server-side technologies (such as ASP.NET, Node.js, PHP).
The manifest is an XML configuration file that defines how the add-in integrates with Office clients by specifying settings and capabilities such as:
The URL of the add-in's web application.
The add-in's display name, description, ID, version, and default locale.
How the add-in integrates with Excel, including any custom UI that the add-in creates (ribbon buttons, context menus, and so on).
Permissions that the add-in requires, such as reading and writing to the document.
To enable end users to install and use an Excel add-in, you must publish its manifest either to AppSource or to an add-ins catalog.
Capabilities of an Excel add-in
In addition to interacting with the content in the workbook, Excel add-ins can add custom ribbon buttons or menu commands, insert task panes, add custom functions, open dialog boxes, and even embed rich, web-based objects such as charts or interactive visualizations within a worksheet.
Add-in commands
Add-in commands are UI elements that extend the Excel UI and start actions in your add-in. You can use add-in commands to add a button on the ribbon or an item to a context menu in Excel. When users select an add-in command, they initiate actions such as running JavaScript code, or showing a page of the add-in in a task pane.
Add-in commands
For more information about command capabilities, supported platforms, and best practices for developing add-in commands, see Add-in commands for Excel, Word, and PowerPoint.
Task panes
Task panes are interface surfaces that typically appear on the right side of the window within Excel. Task panes give users access to interface controls that run code to modify the Excel document or display data from a data source.
Task pane
For more information about task panes, see Task panes in Office Add-ins. For a sample that implements a task pane in Excel, see Excel Add-in JS WoodGrove Expense Trends.
Custom functions
Custom functions enable developers to add new functions to Excel by defining those functions in JavaScript as part of an add-in. Users within Excel can access custom functions just as they would any native function in Excel, such as SUM().
Custom function
For more information about custom functions, see Create custom functions in Excel.
Dialog boxes
Dialog boxes are surfaces that float above the active Excel application window. You can use dialog boxes for tasks such as displaying sign-in pages that can't be opened directly in a task pane, requesting that the user confirm an action, or hosting videos that might be too small if confined to a task pane. To open dialog boxes in your Excel add-in, use the Dialog API.
Dialog box
For more information about dialog boxes and the Dialog API, see Dialog boxes in Office Add-ins and Use the Dialog API in your Office Add-ins.
Content add-ins
Content add-ins are surfaces that you can embed directly into Excel documents. You can use content add-ins to embed rich, web-based objects such as charts, data visualizations, or media into a worksheet or to give users access to interface controls that run code to modify the Excel document or display data from a data source. Use content add-ins when you want to embed functionality directly into the document.
Content add-in
For more information about content add-ins, see Content Office Add-ins. For a sample that implements a content add-in in Excel, see Excel Content Add-in Humongous Insurance in GitHub.
JavaScript APIs to interact with workbook content
An Excel add-in interacts with objects in Excel by using the JavaScript API for Office, which includes two JavaScript object models:
Excel JavaScript API: Introduced with Office 2016, the Excel JavaScript API provides strongly-typed Excel objects that you can use to access worksheets, ranges, tables, charts, and more.
Common API: Introduced with Office 2013, the Common API enables you to access features such as UI, dialogs, and client settings that are common across multiple types of Office applications. Because the Common API does provide limited functionality for Excel interaction, you can use it if your add-in needs to run on Excel 2013.
Next steps
Get started by creating your first Excel add-in. Then, learn about the core concepts of building Excel add-ins.
See also
It is well known that World Wide Web contains huge useful data. However, we have to import the data into Microsoft Excel before doing any kind of analysis. There are two methods that you can use to complete this kind of task.
Table of Contents
Scrape data using VBA programming
Get External Data from Web Manually
Suppose that you want to download revenues about top moneymaking movies from this web page, here shows you how to do it easily.
Open Microsoft Excel and click on the Data tab, in the Get External Data group, click From Web. After New Web Query dialog box appears, copy the web address (http://www.the-numbers.com/movie/records/All-Time-Worldwide-Box-Office) into Address field and click on Go button. Excel will start to download the web page as shown in Figure 1.1. Just click on No if you will get a Script Error warning box which is similar to that in below figure. The box will disappear and it has no impact on your import process.
There is an arrow in the yellow box on the upper right corner of New Web Query dialog box. By clicking on it, you can determine whether to show the similar icons before tables or not. For example, there is no arrow icon next to the table in the left panel of Figure 1.2. And there will be an icon (in the right panel) after you click on the arrow button to show icons.
Figure 1.2 [click on the image to get a full view]
Click the arrow icon next to the tables that you want to select. The icons and tables will change and similar to that shown in the left panel of Figure 1.3. After you click on Import; an Import Data dialog box will be prompted. Fill the range (from column A through column H in our case) where you want to put the data and click on OK.
Figure 1.3 [click on the image to get a full view]
The data will be imported into Excel after you click on Ok. If you right click on any cell within the table and select Refresh, Excel will go out and pull out most recent data from a web page.
And you can even set your query data to be refreshed in any fashion you want. Just right click on any cell within the table, select Data Range Properties. In the prompted External Data Range Properties dialog box, you can change Refresh Control settings to change the style. For example, you can specify the query to be refreshed every 60 minutes or when the file is opened.
Scrape data using VBA programming
VBA programming can be used to scrape data from a web page. It is much more useful while difficult when comparing against the first approach. Moreover, you need to understand what HTML is before learning how to scrape data using VBA programming. I recommend you to learn basic knowledge of HTML from this website if you know nothing or little about HTML. And from here, you can learn almost everything related to web scraping using VBA. This article will only show you two examples.
Scrape data from one web page
Suppose that we want to extract company name, email address and contact name from this web page. If you open this web page, you will find that there is a contact block at the bottom. Figure 2.1 shows the contact block and the corresponding source code. Information in red boxes is what we want to need. And those with a green underline are exactly what we need to extract.
Figure 2.1
The following code can help you extract above requested information and put them in the first worksheet.
“IE.document.getElementsByClassName(“contact-details block dark”)” can enable you to get all elements with the class name – contact-details block dark. This web page lists almost all the properties and methods that can be used on HTML elements. You can choose the appropriate one for your own problem.
The innerHTML property can allow you to set or return the content of an HTML element. In our case, it returned the content of the element with class name “contact-details block dark “ and set it to a variable htext. The content (Figure 2.2) can be prompted by ‘Msgbox htext’.
You can see that the text is well structured. That’s why we can use SPLIT function to extract what need. For example, if we take “<p>Company Name:” as a delimiter and formula “Split(htext, “<p>Company Name: “)(1)” can return the whole text after “<p>Company Name:”. For this newly returned text, we can take “<br” as a delimiter and get the text before the first “<br” and that is the company name. In summary, SPLIT function is a flexible tool that you can use to extract almost everything. Other useful functions include LEN, INSTR, LEFT, RIGHT, MID and REPLACE. I will not discuss in details here.
After you click on OK in Figure 2.2, requested data can be imported from the web into Excel worksheet. For example, cell A1 contains Company Name while cell A4 contains company web page address.
Figure 2.3
By adding below code before you save the workbook, you can add a hyperlink to cell A4.
If you click on cell A4, you can revisit the web page. This is useful especially when you have to retrieve data for a lot of companies. Since you can click on any hyperlink to revisit the corresponding web page and add or update any information manually during review later.
Interact with web pages
Above example just illustrates on how to retrieve data from one static web page. But more than often, we are required to extract have interacted with web pages in order to retrieve a large amount of data. Look at Figure 3.1. It shows you how to get to the web page of above example. You can see that there are a lot of industries and for each industry, there are a lot of companies. For example, there are 651 companies in Agribusiness industry. What should we do if we want to extract contact information of all the companies from all the industries?
Figure 3.1 [click on the image to get a full view]
Well, the key point is that how to make VBA interact with web pages like what we do manually. Let’s take S.W.I.S Advantage as an example. Generally, we hope that Excel can click on Agribusiness (top panel of Figure 3.1) and thus trigger IE to direct us to the second web page. In the second web page (bottom panel of Figure 3.1), Excel can click on S.W.I.S Advantage and then IE directs us to page as shown in Figure 2.1 so that we can retrieve contact information of S.W.I.S Advantage.
After entering following code into Visual Basic Editor and submitting the code, you will see that your IE is opened. The first web page appears followed by the second web page. Here you will learn how to get drop-down list element, to select an option and to trigger event after you select the option. “m = IE.document.getElementsByTagName(“option”).Length – 1” will give you a total number of options. This can be used in for next loop.
This part of the code can direct you to the web page shown in Figure 2.1 after Excel click on the first name. All companies’ names are included in the element with the class name of “Name”. Searchobj is a collection and searchobj(i) can return the (i+1)th object. For example, searchobj(1).Click can enable you to visit the web page for RIDLEY CORPORATION (Melbourne).
Finally, here is the whole code that can show you the process of opening IE, browsing web pages and extracting data. The data extracted will be the same as that in Figure 2.4.
In fact, what we need to do is to extract contact information for all companies from all industries, therefore, we need to do use for loop statement to complete this task. Following is the complete code. And you can also find the code in Retrieve contact information for all companies.xlsm which you can download at the end of this article.
The only point that I need to explain is illustrated in Figure 3.2. One web can list only as many as 25 companies. When the total number of companies is greater than 25, there will be more than one page. Figure 3.2 shows that there is a rule to get the address of pages after the first page. It is the result of the concatenating address of the first page, “&pg=” and the actual page number. And for all pages before the last page, the total object number is 25. “IE.document.getElementsByClassName(“SearchTotal”)(0).innerHTML” can return the total number of companies within an industry. In our case, it will be 651. “Int(tot / 25) + 1” can get you the total number of pages. And “Max = (tot Mod 25) – 1” can return the max number of companies on the last page. I will stop here and leave you to figure out how to apply this idea to the code. It is a much better approach for you to grasp code. You can leave a comment if you have questions.
Here shows you part of the final excel. Contact information for all companies within one industry is put together in one worksheet.
Figure 3.3 [click on the image to get a full view]