Dimension parameter macro

I have been trying to use a old macro from NHCad to read inparameter values into SW 2008 from a text file, but cannot get itto work. The macro gives me a 'Run-time error '91': Object variableor With block variable not set' when it gets to the retvalstatement, any ideas on what is going wrong?

I have listed the code below:

'******************************************************************************
' 10/6/99 - chg_dim.swb
' Macro that will prompt for a data file and import dimensionalvalues
' format of data file should be TAB delimeted Dimension name andvalue
' D1@Sketch1 3
' D2@Sketch1 3.22
' D1@BaseExtrude 2.5
'******************************************************************************

Dim swApp As Object
Dim modelDoc As Object
Dim datastr As String
Dim DimName As String
Dim DimValue As Double

Sub main()
Set swApp = GetObject (,"SldWorks.Application")
Set modelDoc = swApp.ActiveDoc
FileName = "data.dat"
FileName = InputBox("Enter File to Open","File Open",FileName)
Open FileName For Input As #1
Do While Not EOF(1)
Line Input #1, datastr
DimName = Left(datastr,Instr(datastr,Chr(9))-1)
DimValue = Val(Right(datastr,Len(datastr)-Instr(datastr,Chr(9))))
retval = modelDoc.Parameter(DimName).SetValue2(DimValue, 1)
Loop
modelDoc.EditRebuild
modelDoc.GraphicsRedraw2
Close #1
End Sub

Thanks!

bob

SolidworksApi macros