Trying to read from Excel, can't find column name. What am I doing wrong?

Trying to read from Excel, can't find column name. What am I doing wrong?

claudio.ibarra
Advocate Advocate
882 Views
2 Replies
Message 1 of 3

Trying to read from Excel, can't find column name. What am I doing wrong?

claudio.ibarra
Advocate
Advocate

The attached file should have two columns. One named "Series" (cell A1), one named "Project" (cell B1). It just has placeholder data right now for project names as a test.

 

The "Series" column will be a set of 3 digit numbers (as a string, because I want the leading zeroes), and the Project column will be a string.

 

The intent is to have a rule that looks at the filename when the rule is run. The expectation is that the first three digits of the filename will match one of the rows in the "Series" column, and if a match is found, to update the "Project" iProperty of the file with the contents of the corresponding "Project" column for that Series number.

 

It's basically re-creating VLOOKUP in Inventor 2020 with iLogic. 

 

The goal is to give the user a button to press to populate the Project name into files without having to retype it, so all of the parts and assemblies in a given series always have the same Project information, which eventually gets displayed on the title block later on.

 

When it runs, I get an error that it couldn't match the column name, but I'm fairly confident they're both just called "Series". 

 

What am I doing wrong?

 

I'm currently using Inventor 2020.

 

This is the code I have:

oDoc = Left(ThisDoc.FileName(False), 3)

GoExcel.Open("C:\InventorWorkspace\ProjectLookup.xls", "Sheet1")
GoExcel.TitleRow = 1 

i = GoExcel.FindRow("C:\InventorWorkspace\ProjectLookup.xls", "Sheet1", "Series", "=", oDoc)

MessageBox.Show(i, oDoc) 'Test -- error occurs before I get here.

'iProperties.Value("Project", "Project") = GoExcel.CurrentRowValue(What_Goes_Here?)

 

0 Likes
Accepted solutions (1)
883 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor
Accepted solution

I can see no error with the code although I did not use your excel sheet. A few checks. 

  • Ensure the filename and extension is correct.
  • Ensure the Column Header is correct in Both Excel Sheet and Code, it is Case sensitive. 

Added in the code below is some error handling if not found

Dim projnumber As String = Left(ThisDoc.FileName(False), 3)

i = GoExcel.FindRow("C:\InventorWorkspace\ProjectLookup.xls", "Sheet1", "Series", "=", projnumber)

If i = -1 Then
	MessageBox.Show("Cannot find Project Number, Exiting!:", "iLogic")
	Return
Else
	iProperties.Value("Project", "Project") = GoExcel.CurrentRowValue("Series")
	MessageBox.Show("Found Project Number :" & projnumber, "iLogic")
End If

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 3

claudio.ibarra
Advocate
Advocate

Turned out something was wrong with my Excel installation. I tested it on a colleague's machine, and the code works! Thank you for your help! 

0 Likes