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

Application.ActiveWorksheet returns nothing

SOLVED
epainter
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

Re: Application.ActiveWorksheet returns nothing

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

Re: Application.ActiveWorksheet returns nothing

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

Re: Application.ActiveWorksheet returns nothing

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!

Re: Application.ActiveWorksheet returns nothing

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

Announcements
Check out the latest
Mathcad Tip
"PTC Mathcad 15 / Prime 1-6 Update."