ilogic add property from excel

ilogic add property from excel

tegstette
Advocate Advocate
527 Views
2 Replies
Message 1 of 3

ilogic add property from excel

tegstette
Advocate
Advocate

HiSmiley Happy

 

I have a small problem... I have this ilogic rule that will add properties into my file from an Excel sheet.

First the user will enter the part number that gives the row where the information is to be found.

But what I do not get to work is: if the part number that the user enters do not exist in the Excel sheet, I want an Error message...

I have tried different things but dont get it to work...

 

Can someone please help? 

 

 

 

' User will give part number in an input box:
strNum = InputBox("Please enter the part number", "Get Data")

' Excel sheet with information, column 1= Part Num, column 2=Description
i = GoExcel.FindRow("c:\export.xlsx", "Sheet1", "Part Num", "=", strNum)

'If strNum Is Not found Then
'MessageBox.Show("Part Number does not exist in Excel sheet", "Error")


'If i <> "Part Num"  Then
If strNum <> "" Then
MessageBox.Show("Part Number does not exist in Excel sheet", "Error")
Else



' Get property from excel
strDesc = GoExcel.CurrentRowValue("Description")

' Add properties
iProperties.Value("Project", "Part Number") = strNum
iProperties.Value("Project", "Description") = strDesc



End If
Best regards
TG

Autodesk Inventor/Vault Professional 2021
Accepted solutions (1)
528 Views
2 Replies
Replies (2)
Message 2 of 3

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi tegstette,

 

In your example, i is returning the row number.

 

You can use this to see what row number is returned:

 

MessageBox.Show("Row Number is: " & i, "iLogic")

 

 

 

When the input is not found, the row number is returned as -1, so you can use something like this to catch the error:

 

 

' User will give part number in an input box:
strNum = InputBox("Please enter the part number", "Get Data")

' Excel sheet with information, column 1= Part Num, column 2=Description
i = GoExcel.FindRow("C:\TEMP\MyWorkBook.xlsx", "Sheet1", "Part Num", "=", strNum)

If i <= 0 Then
MessageBox.Show("Part Number Not Found", "Error")
End If

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 3 of 3

tegstette
Advocate
Advocate

Perfect!

Thank youSmiley Happy

Best regards
TG

Autodesk Inventor/Vault Professional 2021
0 Likes