Reputation: 2330
I created two projects. One project is a windows form, and the other project is an Excel workbook project. I then added the Excel workbook project to the windows form project.
The window form is a welcome page. That page has some buttons that are supposed to open the workbook on a specific worksheet. For example, the screenshot below has a button Summary Worksheet, when the user clicks that button, I want to open the Excel project, on a spreadsheet by that name.
If my welcome page form was part of my Excel workbook project or any other workbook stored on my hard drive, I would know how to open the workbook. But because they are separate projects combined into one, I have no idea how I can access my workbook from the form. I guess I would like to add a reference to the winform for Excel.
I also attached a screenshot of my VS 2012 project window.
Welcome Page
Upvotes: 0
Views: 1630
Reputation: 3702
It is one solution that is holding two projects. When you build the solution then you will have the .exe for your windows form and the .xlsx and .vsto for your Excel workbook. The easiest way to do what you need is to use Excel interop, and you'll need to know the path on disk to your workbook. The code could be something along these lines:
Imports Microsoft.Office.Interop
Dim xlApp as new Excel.Application
xlApp.Visible = True
Dim xlBook as new Excel.Workbook = xlApp.Workbooks.Open("path/toyour/workbook.xlsx")
xlBook.Worksheets("Welcome Sheet").Activate
That should get you started
Upvotes: 1