I guess you are looking for something like this:
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim xlsh As Object
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
' Attach to active Excel object
Set xl = GetObject(, "Excel.Application")
' Get active sheet in Excel
Set xlsh = xl.ActiveSheet
' Get value from Excel cells
row = GetRowIndex("PN9")
column = 2
If row <> -1 Then
While xlsh.Cells(row, column) <> ""
swModel.AddCustomInfo3 "", xlsh.Cells(1, column), swCustomInfoText, xlsh.Cells(row, column) 'Add the Custom Property Name with value. Will not overwrite if there is any existing property.
column = column + 1
MsgBox ("Failed to lookup value")
Function GetRowIndex(lookupValue As String, Optional colToLookup As Integer = 1) As Integer
Dim rowInd As Integer
Dim val As String
rowInd = 1
val = xlsh.Cells(rowInd, colToLookup)
If val = lookupValue Then
GetRowIndex = rowInd
rowInd = rowInd + 1
Loop While val <> ""
GetRowIndex = -1
Please note that there is no such thing as Excel function in SolidWorks API. SolidWorks doesn't propagate any Excel APIs to their interface. But you can use all Excel API function available in native Excel API as you are doing this now.
Regards, Artem Taturevych | Snr. Developer | IC3D ANZ
IC3DSteel – New Steel Solution for SolidWorks
That works! Thanks.
I was wondering if it was possible to use all of the Excel VBA function calls from SW though. Could something like this work?
row = Application.WorksheetFunction.Match(Value, Range, MatchType)