Solved

Excel Add-in ribbon button click event

Posted on 2010-11-22
1
1,673 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
ID: 34192863
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

808 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