referring to an active Excel workbook

Coleman34

Member
Joined
Mar 10, 2015
Messages
5
Programming Experience
1-3
I have an issue that is perplexing me now. Backstory: I have a windows form add in program for excel that opens from inside Excel. I need to refer to the Active Workbook to get the variables (like fullname) to populate correctly. I have this set up:

VB.NET:
Imports Excel = Microsoft.Office.Interop.Excel
<..omitted for brevity...>
        Dim xlApp = New Excel.Application
        Dim xlWorkbook As Excel.Workbook
        Dim xlWorksheet As Excel.Worksheet

If I refer to the workbook explicitly, like so:
VB.NET:
xlWorkbook = xlApp.Workbooks.Open("C:\SQUID File for VBP Trends 2014Q4.xls")

it works as expected. If I refer to it as the active workbook (as it will need to work dynamically with whatever workbook its open in) the variable comes back as "Nothing".

VB.NET:
xlWorkbook = xlApp.ActiveWorkbook

Is there a way to make the variable "xlWorkbook" dynamically refer to whatever workbook is open?
 

Latest posts

Back
Top