Solved

Excel Add-in ribbon button click event

Posted on 2010-11-22
1
1,637 Views
Last Modified: 2012-06-21
Hello,

I'm trying to create an Excel Add-in that consists on a new ribbon tab with custom buttons.

I would like that, for example, when I click on a button on the ribbon, to write something to an already open Excel sheet, like the code that I show below, but with this code, I get the error that I show on the attached picture.

What am I missing here?

Thanks,

jppinto
Imports Microsoft.Office.Tools.Excel



Public Class Ribbon1



    Private Sub btnInserirLinha_Click(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles btnInserirLinha.Click

        Dim objExcelApp As New Excel.Application

        Dim objExcelBook As Excel.Workbook

        Dim objExcelSheet As Excel.Worksheet



        objExcelBook = objExcelApp.ActiveWorkbook

        objExcelSheet = objExcelBook.ActiveSheet

        objExcelSheet.Cells(1, 1) = "Teste"



    End Sub

End Class

Open in new window

Error.JPG
0
Comment
Question by:jppinto
1 Comment
 
LVL 35

Accepted Solution

by:
Miguel Oz earned 500 total points
Comment Utility
if you are using VSTO:
Replace line 6 with:
 Dim objExcelApp As Excel.Application = Globals.ThisAddIn.Application

See my tutorial: (It is C# but it is easy to translate to VB.net)
http://www.eggheadcafe.com/tutorials/aspnet/ff2d1d4b-aedf-4d14-9e60-39a86ccab5d6/using-vsto-addin-to-auto.aspx
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now