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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Application.ActiveWorksheet returns nothing

epainter
1-Visitor

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

ACCEPTED SOLUTION

Accepted Solutions
StuartBruff
23-Emerald III
(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 III
(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 III
(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

Announcements

Top Tags