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
Solved

Reference already open Excel Sheet

Posted on 2010-11-22
1
374 Views
Last Modified: 2012-05-10
Hello,

I'm trying to add a ribbon toolbar into Excel by creating a Add-in in Visual Studio. That ribbon will have butons that, when clicked, will insert some names into the active cell of the active sheet where the button was pressed. For instance, I have a button btnInserirLinha that when I click I want to write "Test" to the cell where the cursor is on the sheet.

I've the following code but this is for reference a closed workbook. I need to reference the actual workbook.

How can I do this?

Thanks for your help.

jppinto
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.Workbooks.Open("c:\STDJUNE.xls")
        objExcelSheet = objExcelBook.ActiveSheet

    End Sub
End Class

Open in new window

0
Comment
Question by:jppinto
1 Comment
 
LVL 12

Accepted Solution

by:
omegaomega earned 500 total points
ID: 34187526
Hello, jppinto,

Are you just looking for the ActiveWorkbook property of the Excel application object?  That is:

     objExcelBook = objExcelApp.ActiveWorkbook

Cheers,
Randy
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET return row from SQL to DataSet and get column values ? 3 97
Variable Event ? 3 36
Assigning handler to UserControls in flowlayoutpanel 4 27
vb.net 1 month apart 11 35
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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