Excel to Inventor 2017

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I would like to have Inventor read my excel spreadsheet and add custom iproperties automatically. I have this code that worked a few years ago however I am having issues with it now. My spreadsheet A1 = SearchField & A2 = 1000. I would like inventor to look at the entire row 1 and if it sees a text value to create the proper custom iproperties with the values that are in row 2. My ultimate goal would be to have a inventor dwg file (not idw) and have the title block automatically fill in based on my excel file. Any help will be greatly appreciated and I thank you in advance.
Public Sub ExcelToIdw()
Dim xlCon As New ADODB.Connection, xlRs As New ADODB.Recordset
Dim strSearchField As String
Dim xlProp(1 To 11) As String
Dim ivApp As Inventor.Application, ivDoc As Document, ivPropSet As PropertySet
Dim idwProp(1 To 11) As Property
Dim i As Integer
xlCon.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\ilogic test.xls;Extended Properties=Excel 8.0;")
xlRs.Open "Select * From [xtoidw$]", xlCon, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic, &H1
strSearchField = "SearchField = 1000"
xlRs.Find (strSearchField)
For i = 1 To 11
If i = 1 Then
xlProp(1) = xlRs("SearchField").Value
GoTo Skip
End If
If IsNull(xlRs("Field " & i)) Then
xlProp(i) = ""
GoTo Skip
End If
xlProp(i) = xlRs("Field " & i).Value
Skip:
Next i
xlRs.Close
xlCon.Close
Set ivApp = ThisApplication
Set ivDoc = ivApp.ActiveDocument
Set ivPropSet = ivDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
For i = 1 To 11
Set idwProp(i) = ivPropSet.Item("Field " & i)
idwProp(i).Value = xlProp(i)
Next i
ivDoc.Update
MsgBox "Drawing Updated", vbInformation, "Program Complete"
End Sub