Message 1 of 4
Accessing parameters from an Excel spreadsheet

Not applicable
06-19-2007
06:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This code comes from IV samples illustrating how to access values from an Excel file. When I use it I get "Type Mismatch" error. Is anyone using this functionality and if so what must be changed to make it work?
Public Sub TableParameters()
Dim oPartDoc As Inventor.PartDocument
' Obtain the active document, this assumes that
' a part document is active in Inventor
Set oPartDoc = ThisApplication.ActiveDocument
'Obtain the Parameters collection
Dim oParams As Parameters
Set oParams = oPartDoc.ComponentDefinition.Parameters
' Add a parameter table using an existing spreadsheet.
oParams.ParameterTables.AddExcelTable "C:\Temp\params.xls", "A1", True
' Accessing a parameters in a linked/embedded file
Dim oParamTableFiles As ParameterTables
Set oParamTableFiles = oParams.ParameterTables
' Traverse through the collection of linked files
Dim oParamTableFile As ParameterTable
For Each oParamTableFile In oParamTableFiles
' Change the linked file to another file
If LCase(oParamTableFile.FileName) = "c:\temp\params.xls" Then
oParamTableFile.FileName = "C:\Temp\newparams.xls"
End If
' Get the Parameters collection from the file
Dim oTableParams As TableParameters
Set oTableParams = oParamTableFile.TableParameters
' Traverse through the table parameters collection and display them
Dim iNumTableParams As Long
Debug.Print "TABLE PARAMETER VALUES"
For iNumTableParams = 1 To oTableParams.Count
' Display the name
Debug.Print " Name: " & oTableParams.Item(iNumTableParams).Name
' Display the expression
Debug.Print " Expression: " & oTableParams.Item(iNumTableParams).Expression
' Display the value. This will be in database units.
Debug.Print " Value: " & oTableParams.Item(iNumTableParams).Value
Next iNumTableParams
Next
End Sub
Thanks,
Jon
Public Sub TableParameters()
Dim oPartDoc As Inventor.PartDocument
' Obtain the active document, this assumes that
' a part document is active in Inventor
Set oPartDoc = ThisApplication.ActiveDocument
'Obtain the Parameters collection
Dim oParams As Parameters
Set oParams = oPartDoc.ComponentDefinition.Parameters
' Add a parameter table using an existing spreadsheet.
oParams.ParameterTables.AddExcelTable "C:\Temp\params.xls", "A1", True
' Accessing a parameters in a linked/embedded file
Dim oParamTableFiles As ParameterTables
Set oParamTableFiles = oParams.ParameterTables
' Traverse through the collection of linked files
Dim oParamTableFile As ParameterTable
For Each oParamTableFile In oParamTableFiles
' Change the linked file to another file
If LCase(oParamTableFile.FileName) = "c:\temp\params.xls" Then
oParamTableFile.FileName = "C:\Temp\newparams.xls"
End If
' Get the Parameters collection from the file
Dim oTableParams As TableParameters
Set oTableParams = oParamTableFile.TableParameters
' Traverse through the table parameters collection and display them
Dim iNumTableParams As Long
Debug.Print "TABLE PARAMETER VALUES"
For iNumTableParams = 1 To oTableParams.Count
' Display the name
Debug.Print " Name: " & oTableParams.Item(iNumTableParams).Name
' Display the expression
Debug.Print " Expression: " & oTableParams.Item(iNumTableParams).Expression
' Display the value. This will be in database units.
Debug.Print " Value: " & oTableParams.Item(iNumTableParams).Value
Next iNumTableParams
Next
End Sub
Thanks,
Jon