Porting GoExcel command from VBA to VB.Net add-in.

Porting GoExcel command from VBA to VB.Net add-in.

awatt
Advocate Advocate
1,120 Views
5 Replies
Message 1 of 6

Porting GoExcel command from VBA to VB.Net add-in.

awatt
Advocate
Advocate

I'm trying to convert a VBA macro to an add-in.  But it uses the GoExcel function to acess an .xls file.  Does anyone have an example of how to get this functionality in VB.net?

What .dll's do I need to reference? What Objects to I need to get?  I found a IGoExcel interface, but I'm getting nowhere with that alone.

 

(Inventor 2015, VS 10)

0 Likes
Accepted solutions (1)
1,121 Views
5 Replies
Replies (5)
Message 2 of 6

rjay75
Collaborator
Collaborator

To interact with Excel the .NET way you would use VSTO (Visual Studio Tools for Office). Here's the msdn page for getting started with Excel. Not as simple as the VBA method. 

0 Likes
Message 3 of 6

GeorgK
Advisor
Advisor

It depends on what you are trying to do. There are some examples:

http://www.siddharthrout.com/vb-dot-net-and-excel/

 

You can post your code and we can take a look at it.

0 Likes
Message 4 of 6

awatt
Advocate
Advocate

On closer examination, this portion of the code I'm porting is an external iLogic file, not VBA.

 

First a user parameter is created, then a multi-value list is read from an .xlsx file.

The contents of the .xlsx file are somewhat fluid, so I don't want to embed them in the code and recompile every time there's a change.

 

iLogicVb.UpdateWhenDone = True
MultiValue.UpdateAfterChange = True

 

Try
   Code_param = Parameter("Comm_Code_List")
Catch
   oParameter=oMyParameter.AddByValue("Comm_Code_List", "-", UnitsTypeEnum.kTextUnits)
End Try

 

ExcelFile = "\\srv8-2010-FS\VNSMASTER\Engineering\Engineering Standards\Inventor 2013\CAD Standards\Documents\Code Lists.xlsx"

MultiValue.List("Comm_Code_List") = GoExcel.CellValues(ExcelFile, "Commodity Code", "A2", "A150")

0 Likes
Message 5 of 6

awatt
Advocate
Advocate

I've made some further progress:

I found the Interop.Excel.dll in the Program Files\Common Files\Autodesk Shared\Extensions 2014\Framework\Interop directory.

 

It seems to give access to the workbook object, and the workbooks class has an open method.

 

I'll have to try it, but I'm still wondering how to define the application object without opening Excel.

 

0 Likes
Message 6 of 6

Anonymous
Not applicable
Accepted solution

There may be some of this that will help you:

 

https://reinventinginventor.wordpress.com/2014/11/24/re-writing-the-goexcel-functions-for-use-in-ilo...

 

But I don't thikn there's a way to get the data from excel without having an application open. You can have a version of excel open but not visible to the user (ExcelApp.Visible = False, if i remember correctly)

0 Likes