0

Can anyone tell me why the activeworksheet object MCWS is not being created by the following VB Script please? It is the code for a combobox in a mathcad worksheet. Thanks

Public Sub SizeBoxEvent_Start()
  Dim objEX
  Dim objMC

  Dim MCWS
  Dim objEXWB
  Dim objEXWS
  Dim intLineNo
  Dim objRange
End Sub

Sub SizeBoxEvent_Exec(Inputs,Outputs)
  Set objMC = CreateObject("MathCad.Application")
  Set MCWS = objMC.ActiveWorkSheet

  Set objEX = CreateObject("Excel.Application")
  Set objEXWB = GetObject("C:\UB_Dims.xls")

  Set objEXWS = objEXWB.worksheets("UB")

  Dim MyList(71)

  For i = 0 to 71
    Mylist(i) = CStr(objEXWS.cells(i+3,1))
    'MsgBox Mylist(i)
  Next

  SizeBox.List() = MyList
  intLineNo = SizeBox.ListIndex + 3
  objRange = "A" & intLineNo & ":U" & intLineNo

  Dim varDimProps(21)
  Dim varDimName(21)

  For i = 1 to 21
    varDimProps(i) = objEXWS.cells(intLineNo,i)
    varDimName(i) = CStr(objEXWS.cells(1,i))
  Next

  MCWS.SetValue "Size", ABC
  MCWS.SetValue "M", 288
  MCWS.SetValue "D", 203

  Outputs(0).Value = varDimProps
End Sub

Sub SizeBoxEvent_Stop()
  Rem TODO: Add your code here
End Sub
aphoria
  • 19,796
  • 7
  • 64
  • 73

1 Answers1

1

I haven't used Public subs, so I don't know if your declarations will carry over to other subs. Here's something I picked from the PTC forum that works in Excel 2007 with Mathcad 15.0 (I understand that the excel add in is broken for later excel versions).

My guess is that you should define your objects in the functions that use them. Also, I don't think you can use Activeworksheet for the MathCad worksheet.

Private Function RunMCAD(InputFile As String)
Dim MC As Object
Set MC = CreateObject("Mathcad.Application")
MC.Visible = True

Set Wk = MC.Worksheets
Set WS = Wk.Open("C:\RDDA\RDDA 2014-10-16_excel.xmcd")
WS.SetValue "InputFile", InputFile

WS.Recalculate
WS.Save
WS.Close False
MC.Quit
RunMCAD = "Done"
End Function
TostCrusty
  • 11
  • 1