Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
WCrihfield
in reply to: OPthorsager

Interacting with another application (like Excel) from Inventor is often a little more complicated of an endeavor than it seems like it should be, and how well it works seems to change over time (with updates and new versions), and from one person to the next.  The 'GetObject' and 'CreateObject' method usually return different Types of objects for me, which can be confusing.  The actual Excel.Application object is an Interface, which we can not use the 'New' keyword to create a new instance of, but there is also an Excel.ApplicationClass Type, which we often get a reference to, which we can use 'New' keyword to get, but should not use directly (for internal use).  That's why we usually include the TryCast statements in there, trying to cast (or convert) the one Type to the other Type, that we can use.

 

On a side note, when going the UsedRange route, there is a 'method' of the resulting Range object that we can use called Range.SpecialCells.  The first thing it wants as input is a variation of the XLCellType Enum, which there is a variation of to specify the last cell in the used range (XlCellType.xlCellTypeLastCell).  That method returns a Range matching the input criteria, which in this case should be a sing cell.  Then you can use the resulting Range.Row or Range.Column properties, which both return an Integer, which represents the Index of that row or column, where Column A would be 1 (not zero), and so on.

And by the way, all my links have been to the documentation for accessing Excel via VB.NET, not via VBA, because I was assuming you would be using iLogic, which uses vb.net.  But I believe that most of the same objects and properties exist on the VBA side also, if you are planning on keeping your code in VBA macros, instead of iLogic rules.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)