Solved

Reference already open Excel Sheet

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

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 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

18 Experts available now in Live!

Get 1:1 Help Now