Excel 2013 add-ins in Visual Studio 2012: Getting started for VSTO developers
Posted on Monday, April 8th, 2013 at 9:24 am by .
So we’ve taken a look at how to get started with developing Office add-ins using Add-in Express when you have a Visual Studio Tool for Office (VSTO) background and How to create Outlook 2013 add-in in VS 2012.
In this article we’ll have a look at how you, as a VSTO developer, can get started developing add-ins for Excel using Add-in Express for Office and .net and Visual Studio 2012 (C#, VB.NET, C++ .NET are supported). The article covers:
- Creating the Excel add-in project
- Accessing Excel application objects and events
- Excel ribbons, command bars and context menu UI designers
- XLL add-ins, user defined functions (UDF) and Real-time data servers (RTD)
Creating the Excel add-in project in VS 2012
As with all Add-in Express projects, you start your Excel add-in project by creating a new ADX COM Add-in in Visual Studio.
A wizard will then guide you through some important steps. The first is to (a) choose which programming language you would like to write your add-in with – C#. VB.NET and C++/NET are supported; and (b) what the minimum version of Office is that it should support. For example, if you choose Microsoft Office 2003, your add-in will work with all versions of Excel from 2003 up to Excel 2013.
The second step is to choose the supported Microsoft Office application. This is unlike VSTO where your add-in can only support one Microsoft Office application at a time. Add-in Express allows you to support multiple applications from one project.
Since you only need to support Excel, you only select Excel from the list of supported applications.
Accessing Excel application objects and events
When using VSTO you can access the Excel application object via the Application object, e.g.:
this.Application
Add-in Express provides a specific component to make handling and creating an Excel event handler very easy. In order to respond to Excel events, you first need to add a new Microsoft Excel Events component to the AddinModule designer surface.
This component exposes all the available events for Microsoft Excel. To add an event handler for a specific Excel event, select the Excel events component and double-click next to the event name in the list of events in the properties window.
This will then automatically generate the event handler code inside the AddinModule.cs class for you e.g.:
public Excel._Application ExcelApp { get { return (HostApplication as Excel._Application); } }
Excel ribbons, command bars and context menu UI designers
The Add-in Express toolset is built around a collection of visual designers. With these designers you can visually design the UI for your Excel add-in.
Creating a custom Excel ribbon
VSTO does provide a basic visual ribbon designer for simple ribbon designs as well as an XML based ribbon designer for complex ribbon layouts. With Add-in Express you do not need to use XML at all, you can design all your Excel ribbon tabs using the visual designer no matter what the level of complexity is.
To create a custom ribbon tab, you first need to add its component to the AddinModule’s designer surface.
Using the visual designer you can add a variety of ribbon controls to your own custom Excel ribbon tab. Add-in Express provides access to the following Ribbon controls:
- Ribbon Group
- Ribbon Box
- Ribbon Button Group
- Ribbon Button
- Ribbon Split Button
- Ribbon Label
- Ribbon Check box
- Ribbon Edit box
- Ribbon Combo box
- Ribbon Dropdown
- Ribbon Gallery
- Ribbon Menu
- Ribbon Separator
- Ribbon Menu Separator
- Ribbon Dialog box Launcher
All the ribbon controls are accessible via their own toolbar inside the Add-in Express visual designer:
Creating a custom Excel toolbar
If you want to create toolbars for Excel 2003 and earlier, Add-in Express provides visual designers for that too. First add a Command Bar component to the AddinModule designer surface.
By setting the SupportedApps property of the Command Bar component to Excel, you tell Add-in Express to only show this particular custom command bar in Excel. You can then design it in a similar fashion as the Ribbon tab.
Add-in Express provides access to the following command bar controls:
- Command bar button
- Command bar combo box
- Command bar dropdown list
- Command bar edit box
- Command bar pop-up
Creating a custom Excel context menu
Custom context-menus can provide powerful additional functionality for Excel users. The add-in Express Context Menu component allows you to create your own context-menus for Excel. In order to use this, first add the component to the AddinModule designer.
Then design the context-menu using the built-in visual designer as well as choose which Excel context-menu your menu should be added to. Add-in Express provides a long list of all the built-in Excel context-menus which you can specify in the CommandBarName property.
XLL add-ins, user defined functions (UDF) and Real-time data servers (RTD)
Creating user defined functions and RTD servers with VSTO is simply not possible. Luckily, Add-in Express provides project and item types to easily create your own RTD Server or XLL add-in.
Creating an XLL add-in
To create an XLL add-in, create a new ADX XLL Add-in project in Visual Studio.
The XLL Add-in project also provides a visual designer surface called XLLModule. To create your own user defined functions, start by adding an Excel Function Category.
The next step would be to add functions by selecting the category and using the visual designer.
The function name is automatically assigned based up what you’ve called your method inside the XLLModule class, e.g.:
public static string AllSupportedExcelTypes(object arg) { if (arg is double) return "Double: " + (double)arg; else if (arg is string) return "String: " + (string)arg; else if (arg is bool) return "Boolean: " + (bool)arg; else if (arg is AddinExpress.MSO.ADXExcelError) return "ExcelError: " + arg.ToString(); else if (arg is object[,]) return string.Format("Array[{0},{1}]", ((object[,])arg).GetLength(0), ((object[,])arg).GetLength(1)); else if (arg is System.Reflection.Missing) return "Missing"; else if (arg == null) return "Empty"; else if (arg is AddinExpress.MSO.ADXExcelRef) { AddinExpress.MSO.ADXExcelRef reference = arg as AddinExpress.MSO.ADXExcelRef; return string.Format("Reference [{0},{1},{2},{3}]", reference.ColumnFirst, reference.RowFirst, reference.ColumnLast, reference.RowLast); } else if (arg is short) return "Short: " + (short)arg; else return "Unknown Type"; }
See How to create an Excel XLL add-in for full details.
Creating an Excel RTD server add-in
To create an RTD server add-in, you need to create a new ADX RTD Server project in Visual Studio.
The RTD Server project follows the same pattern and provides a RTDServerModule designer surface. You need to add a new RTD Topic to the designer surface by right-clicking on it and selecting «Add RTD Topic» from the context-menu.
From there on onwards, create a new event handler for the RTD topic’s RefreshData event and add your own logic.
private object adxrtdTopic1_RefreshData(object sender) { Random rand = new Random(); return rand.Next(1,1000); }
See How to create an Excel Real-Time Data server for step-by-step instructions.
So, when you need to kick things up a notch when developing Excel add-ins, you need to fire up Add-in Express and get going.
Thank you for reading. Until next time, keep coding!
Office 2013 add-ins and VS 2012: Getting started for VSTO developers
- Part 1: Office 2013 addin in VS 2012: project types and solution architecture
- Part 2: Outlook 2013 add-in development in Visual Studio 2012
You may also be interested in:
- Creating Excel 2010, 2007 addin. Customizing Excel Ribbon: C#, VB.NET
- Video: Creating Excel COM add-in using C#, VB.NET
- Special features for Excel plug-in developers
- Remove From My Forums
-
Question
-
Hello guys,
I’m trying to create a project using virtual studio 2012 to excel. I do have office 2013 installed in my machine, but and i try to create a project for excel in visual studio, its says that i do not have excel installed in my machine.
if there is a solution,
Do you know how to solve it?
Answers
-
-
Marked as answer by
Wednesday, December 19, 2012 4:25 AM
-
Marked as answer by
-
Hi Leohermoso,
Thank you for posting in the MSDN Forum.
Did you chose the right application template? In order to create Excel 2013 project, you’ll need to choose Excel 2013 Add-in Excel 2013 Template or Excel 2013 Workbook.
If you are sure that you have chosen the right application template, please tell me:
- System version and bit.
- Office version(s) and bit.
- If you have multiple versions’ of Office installed, tell me the installation sequence.
I think your issue can be solved by doing things below.
- Install all the update patches.
- Update your Office to the newest release.
- Update your Visual Studio Tools for Office to newest.
Hope it helps.
Best regards,
Quist Zhang [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.-
Edited by
Quist Zhang
Tuesday, December 18, 2012 7:28 AM -
Marked as answer by
Quist Zhang
Tuesday, December 18, 2012 7:33 AM
Содержание
- Visual studio 2012 and excel
- Answered by:
- Question
- Answers
- Visual studio 2012 and excel
- Answered by:
- Question
- Answers
- Excel 2013 add-ins in Visual Studio 2012: Getting started for VSTO developers
- Creating the Excel add-in project in VS 2012
- Accessing Excel application objects and events
- Excel ribbons, command bars and context menu UI designers
- Creating a custom Excel ribbon
- Creating a custom Excel toolbar
- Creating a custom Excel context menu
- XLL add-ins, user defined functions (UDF) and Real-time data servers (RTD)
- Creating an XLL add-in
- Creating an Excel RTD server add-in
- Visual studio 2012 and excel
- Answered by:
- Question
- Answers
Visual studio 2012 and excel
This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.
Answered by:
Question
I’m trying to create a project using virtual studio 2012 to excel. I do have office 2013 installed in my machine, but and i try to create a project for excel in visual studio, its says that i do not have excel installed in my machine.
if there is a solution,
Do you know how to solve it?
Answers
Firstly, I advise you repair the office 2013 form task pane, and then instal Microsoft office developer Tools for Visual Studio -Preview 2 by Web Platform Installer 4.0
I think this soluction can help you.
Please let me know if you have any other question.
Thank you for posting in the MSDN Forum.
Did you chose the right application template? In order to create Excel 2013 project, you’ll need to choose Excel 2013 Add-in Excel 2013 Template or Excel 2013 Workbook.
If you are sure that you have chosen the right application template, please tell me:
- System version and bit.
- Office version(s) and bit.
- If you have multiple versions’ of Office installed, tell me the installation sequence.
I think your issue can be solved by doing things below.
- Install all the update patches.
- Update your Office to the newest release.
- Update your Visual Studio Tools for Office to newest.
Quist Zhang [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Источник
Visual studio 2012 and excel
This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.
Answered by:
Question
I’m trying to create a project using virtual studio 2012 to excel. I do have office 2013 installed in my machine, but and i try to create a project for excel in visual studio, its says that i do not have excel installed in my machine.
if there is a solution,
Do you know how to solve it?
Answers
Firstly, I advise you repair the office 2013 form task pane, and then instal Microsoft office developer Tools for Visual Studio -Preview 2 by Web Platform Installer 4.0
I think this soluction can help you.
Please let me know if you have any other question.
Thank you for posting in the MSDN Forum.
Did you chose the right application template? In order to create Excel 2013 project, you’ll need to choose Excel 2013 Add-in Excel 2013 Template or Excel 2013 Workbook.
If you are sure that you have chosen the right application template, please tell me:
- System version and bit.
- Office version(s) and bit.
- If you have multiple versions’ of Office installed, tell me the installation sequence.
I think your issue can be solved by doing things below.
- Install all the update patches.
- Update your Office to the newest release.
- Update your Visual Studio Tools for Office to newest.
Quist Zhang [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Источник
Excel 2013 add-ins in Visual Studio 2012: Getting started for VSTO developers
So we’ve taken a look at how to get started with developing Office add-ins using Add-in Express when you have a Visual Studio Tool for Office (VSTO) background and How to create Outlook 2013 add-in in VS 2012.
In this article we’ll have a look at how you, as a VSTO developer, can get started developing add-ins for Excel using Add-in Express for Office and .net and Visual Studio 2012 (C#, VB.NET, C++ .NET are supported). The article covers:
Creating the Excel add-in project in VS 2012
As with all Add-in Express projects, you start your Excel add-in project by creating a new ADX COM Add-in in Visual Studio.
A wizard will then guide you through some important steps. The first is to (a) choose which programming language you would like to write your add-in with – C#. VB.NET and C++/NET are supported; and (b) what the minimum version of Office is that it should support. For example, if you choose Microsoft Office 2003, your add-in will work with all versions of Excel from 2003 up to Excel 2013.
The second step is to choose the supported Microsoft Office application. This is unlike VSTO where your add-in can only support one Microsoft Office application at a time. Add-in Express allows you to support multiple applications from one project.
Since you only need to support Excel, you only select Excel from the list of supported applications.
Accessing Excel application objects and events
When using VSTO you can access the Excel application object via the Application object, e.g.:
this.Application
Add-in Express provides a specific component to make handling and creating an Excel event handler very easy. In order to respond to Excel events, you first need to add a new Microsoft Excel Events component to the AddinModule designer surface.
This component exposes all the available events for Microsoft Excel. To add an event handler for a specific Excel event, select the Excel events component and double-click next to the event name in the list of events in the properties window.
This will then automatically generate the event handler code inside the AddinModule.cs class for you e.g.:
Excel ribbons, command bars and context menu UI designers
The Add-in Express toolset is built around a collection of visual designers. With these designers you can visually design the UI for your Excel add-in.
Creating a custom Excel ribbon
VSTO does provide a basic visual ribbon designer for simple ribbon designs as well as an XML based ribbon designer for complex ribbon layouts. With Add-in Express you do not need to use XML at all, you can design all your Excel ribbon tabs using the visual designer no matter what the level of complexity is.
To create a custom ribbon tab, you first need to add its component to the AddinModule’s designer surface.
Using the visual designer you can add a variety of ribbon controls to your own custom Excel ribbon tab. Add-in Express provides access to the following Ribbon controls:
- Ribbon Group
- Ribbon Box
- Ribbon Button Group
- Ribbon Button
- Ribbon Split Button
- Ribbon Label
- Ribbon Check box
- Ribbon Edit box
- Ribbon Combo box
- Ribbon Dropdown
- Ribbon Gallery
- Ribbon Menu
- Ribbon Separator
- Ribbon Menu Separator
- Ribbon Dialog box Launcher
All the ribbon controls are accessible via their own toolbar inside the Add-in Express visual designer:
Creating a custom Excel toolbar
If you want to create toolbars for Excel 2003 and earlier, Add-in Express provides visual designers for that too. First add a Command Bar component to the AddinModule designer surface.
By setting the SupportedApps property of the Command Bar component to Excel, you tell Add-in Express to only show this particular custom command bar in Excel. You can then design it in a similar fashion as the Ribbon tab.
Add-in Express provides access to the following command bar controls:
- Command bar button
- Command bar combo box
- Command bar dropdown list
- Command bar edit box
- Command bar pop-up
Custom context-menus can provide powerful additional functionality for Excel users. The add-in Express Context Menu component allows you to create your own context-menus for Excel. In order to use this, first add the component to the AddinModule designer.
Then design the context-menu using the built-in visual designer as well as choose which Excel context-menu your menu should be added to. Add-in Express provides a long list of all the built-in Excel context-menus which you can specify in the CommandBarName property.
XLL add-ins, user defined functions (UDF) and Real-time data servers (RTD)
Creating user defined functions and RTD servers with VSTO is simply not possible. Luckily, Add-in Express provides project and item types to easily create your own RTD Server or XLL add-in.
Creating an XLL add-in
To create an XLL add-in, create a new ADX XLL Add-in project in Visual Studio.
The XLL Add-in project also provides a visual designer surface called XLLModule. To create your own user defined functions, start by adding an Excel Function Category.
The next step would be to add functions by selecting the category and using the visual designer.
The function name is automatically assigned based up what you’ve called your method inside the XLLModule class, e.g.:
Creating an Excel RTD server add-in
To create an RTD server add-in, you need to create a new ADX RTD Server project in Visual Studio.
The RTD Server project follows the same pattern and provides a RTDServerModule designer surface. You need to add a new RTD Topic to the designer surface by right-clicking on it and selecting «Add RTD Topic» from the context-menu.
From there on onwards, create a new event handler for the RTD topic’s RefreshData event and add your own logic.
So, when you need to kick things up a notch when developing Excel add-ins, you need to fire up Add-in Express and get going.
Thank you for reading. Until next time, keep coding!
Источник
Visual studio 2012 and excel
This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.
Answered by:
Question
I’m trying to create a project using virtual studio 2012 to excel. I do have office 2013 installed in my machine, but and i try to create a project for excel in visual studio, its says that i do not have excel installed in my machine.
if there is a solution,
Do you know how to solve it?
Answers
Firstly, I advise you repair the office 2013 form task pane, and then instal Microsoft office developer Tools for Visual Studio -Preview 2 by Web Platform Installer 4.0
I think this soluction can help you.
Please let me know if you have any other question.
Thank you for posting in the MSDN Forum.
Did you chose the right application template? In order to create Excel 2013 project, you’ll need to choose Excel 2013 Add-in Excel 2013 Template or Excel 2013 Workbook.
If you are sure that you have chosen the right application template, please tell me:
- System version and bit.
- Office version(s) and bit.
- If you have multiple versions’ of Office installed, tell me the installation sequence.
I think your issue can be solved by doing things below.
- Install all the update patches.
- Update your Office to the newest release.
- Update your Visual Studio Tools for Office to newest.
Quist Zhang [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Источник
So I’m working on a project that uses an excel file to add «descriptions to user controls. As of right now, my code opens the excel file using an absolute path, like so
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:absolute pathfilename.xlsx", Type.Missing, Type.Missing
, Type.Missing, Type.Missing, Type.Missing, Type.Missing
, Type.Missing, Type.Missing, Type.Missing, Type.Missing
, Type.Missing, Type.Missing);
which works just fine.
I then tried renaming the file (just to make sure that the C: file wasn’t being opened for some odd reason) and added it to my project so that I wouldn’t have to depend on being able to access a particular drive (i.e the file could be opened because it’s associated with the project). Then I tried the following code:
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"newfileName.xlsx", Type.Missing, Type.Missing
, Type.Missing, Type.Missing, Type.Missing, Type.Missing
, Type.Missing, Type.Missing, Type.Missing, Type.Missing
, Type.Missing, Type.Missing);
which gave me this:
«Additional information: ‘newfileName.xlsx’ could not be found. Check the spelling of the file name, and verify that the file location is correct.»
I was wondering what is the correct way to add an excel file to a project and open it using a relative path name?
-
Jan 12th, 2016, 01:20 PM
#1
Thread Starter
Lively Member
Building an Excel workbook in Visual Studio 2012 Professional
Hello, I am in need of some information. I have never actually built an excel workbook inside visual studio. I went ahead started a new project inside Visual Studio by opening a template inside
«TemplatesVisual BasicOfficeExcel 2010 Workbook»
and wrote some code inside sheet1 for excel to do some stuff with vb.net and it works just fine when I run it inside Visual Studio before building it. It is supposed to launch the code as soon as excel starts up by using a Sheet_Startup Event.
However after building it, and I launch the excel file, it doesn’t do anything. Isn’t it supposed to run the code you wrote?
How can I get it to work?
-
Jan 12th, 2016, 03:15 PM
#2
Re: Building an Excel workbook in Visual Studio 2012 Professional
by using a Sheet_Startup Event.
i have never seen such an event, i would have thought the workbook_open event
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Nextdim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jan 13th, 2016, 10:20 AM
#3
Thread Starter
Lively Member
Re: Building an Excel workbook in Visual Studio 2012 Professional
There is in-fact a Sheet_startup event. However it doesn’t seem to work like I thought it would. It won’t work at all to be honest. Maybe I am not building the workbook correctly, but after pressing «F5» in the VS application it successfully builds the workbook, but when you launch the workbook, it does nothing. Is there more too it than that?
So I tried using the Workbook Startup event. I am trying to call a subroutine on sheet1 like the code shows:
Private Sub ThisWorkbook_Startup() Handles Me.Startup
Sheets(«Sheet1»).ProcessNXData()
End Sub
But with no success. It tells me that it cannot find the subroutine ProcessNXData().
Could it be that it cannot see the subroutine because the subroutine is inside of a class?
If that is the case, how do I properly call the subroutine?
-
Jan 13th, 2016, 03:23 PM
#4
Re: Building an Excel workbook in Visual Studio 2012 Professional
what version of excel are you using?
you could try putting the ProcessNXData into a standard module
or you could try xlapp.run Sheets(«Sheet1»).ProcessNXData(), change application object to suit
another way to try is sheet1.ProcessNXData()in all cases the sub must be public, default in an object module is private
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Nextdim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 19th, 2016, 11:05 PM
#5
Registered User
Re: Building an Excel workbook in Visual Studio 2012 Professional
hello, im also facing this problem. i want VB.net link to excel at the same time. ive made the code but the excel re-opened each time the serial reads the analog data from the sensor
im trying to do something like this —> https://www.youtube.com/watch?v=OFDT_DjmUQo
can anyone help me? i’ll post my code here later if you guys willing to help…
-
Mar 20th, 2016, 03:02 AM
#6
Re: Building an Excel workbook in Visual Studio 2012 Professional
if you guys willing to help…
that is why we come here
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Nextdim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete