Solved

Reference already open Excel Sheet

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

772 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