[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 383
  • Last Modified:

Reference already open Excel Sheet

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
jppinto
Asked:
jppinto
1 Solution
 
omegaomegaDeveloperCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now