Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Excel Add-in ribbon button click event

Posted on 2010-11-22
1
Medium Priority
?
1,846 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

597 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