Solved

Excel Add-in ribbon button click event

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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