Solved

Reference already open Excel Sheet

Posted on 2010-11-22
1
362 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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
DataGridView 2 28
Find value in LINQ result ? 4 17
How to change a specific bit from a file 2 19
Set form below another form 3 24
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

12 Experts available now in Live!

Get 1:1 Help Now