Solved

Excel Add-in ribbon button click event

Posted on 2010-11-22
1
1,657 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linq Help 1 35
Runtime Error 2 28
Server Error 11 47
I need help viewing multiple page TIFF image in my WPF with VB.Net code-behind application 7 16
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

16 Experts available now in Live!

Get 1:1 Help Now