cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Application.ActiveWorksheet returns nothing

epainter
1-Newbie

Application.ActiveWorksheet returns nothing

I am embedding some VB in a Scripted Object within a MathCad worksheet. I am trying to get the Worksheet object so I can get/manipulate some values in the sheet, but when I call ActiveWorksheet (or Worksheets for that matter) on the Application object, nothing is returned.

I am inexperienced with VB so forgive anything weird I am doing, but feel free to point it out. Here is what I have basically. I get an error object worksheet is required on the last line of the Sub.

Sub getValueEvent_Exec(Inputs,Outputs)

  Dim objMC

  Dim value

  Dim worksheet

  

  Set objMC = CreateObject("MathCad.Application")

  Set worksheet =objMC.ActiveWorksheet

  Set value = worksheet.getValue("value")

End Sub

Thanks,

Evan

1 ACCEPTED SOLUTION

Accepted Solutions
StuartBruff
23-Emerald II
(To:epainter)

Evan Painter wrote:

I am embedding some VB in a Scripted Object within a MathCad worksheet. I am trying to get the Worksheet object so I can get/manipulate some values in the sheet, but when I call ActiveWorksheet (or Worksheets for that matter) on the Application object, nothing is returned.

I am inexperienced with VB so forgive anything weird I am doing, but feel free to point it out. Here is what I have basically. I get an error object worksheet is required on the last line of the Sub.

Sub getValueEvent_Exec(Inputs,Outputs)

  Dim objMC

  Dim value

  Dim worksheet

  Set objMC = CreateObject("MathCad.Application")

  Set worksheet =objMC.ActiveWorksheet

  Set value = worksheet.getValue("value")

End Sub

Can I just clarify what you're doing here?  You are working inside Mathcad. You have create a worksheet and have added a component (TextBox, ListBox, etc) to the worksheet and are now trying to work with the script inside that component?

Is so, the current worksheet is defined by default and simply named worksheet, so you don't have to go through the rigmarole of creating a Mathcad object.

Stuart

View solution in original post

3 REPLIES 3
StuartBruff
23-Emerald II
(To:epainter)

Evan Painter wrote:

I am embedding some VB in a Scripted Object within a MathCad worksheet. I am trying to get the Worksheet object so I can get/manipulate some values in the sheet, but when I call ActiveWorksheet (or Worksheets for that matter) on the Application object, nothing is returned.

I am inexperienced with VB so forgive anything weird I am doing, but feel free to point it out. Here is what I have basically. I get an error object worksheet is required on the last line of the Sub.

Sub getValueEvent_Exec(Inputs,Outputs)

  Dim objMC

  Dim value

  Dim worksheet

  Set objMC = CreateObject("MathCad.Application")

  Set worksheet =objMC.ActiveWorksheet

  Set value = worksheet.getValue("value")

End Sub

Can I just clarify what you're doing here?  You are working inside Mathcad. You have create a worksheet and have added a component (TextBox, ListBox, etc) to the worksheet and are now trying to work with the script inside that component?

Is so, the current worksheet is defined by default and simply named worksheet, so you don't have to go through the rigmarole of creating a Mathcad object.

Stuart

Perfect! Yeah your assessment of what I was doing is correct. I was making it much harder than it needed to be. Thanks for the help!

StuartBruff
23-Emerald II
(To:epainter)

Evan Painter wrote:

Perfect! Yeah your assessment of what I was doing is correct. I was making it much harder than it needed to be. Thanks for the help!

No worries.  I think most of us have had to bang our heads against the difficulty of finding out how to use scripting when all we've got to go on is the documentation!

Stuart

Top Tags