Skip to main content
12-Amethyst
February 25, 2022
Solved

Know the state of mathcad calculation through API Excel

  • February 25, 2022
  • 2 replies
  • 1608 views

Hi,

 

I had conflicts between Excel VBA and Mathcad. Basically, VBA seems to not wait for Mathcad to finish its calculation, leading to errors (e.g. not retrieving outputs). I solved most of these issues by adding the command

Application.Wait (Now + TimeValue("xxx"))

which forces VBA to wait xxx seconds before resuming the code.

 

Still, I was wondering if there is a way to know from VBA the state of Mathcad (is it calculating or is it ready to start calculations?). That way, I can tell VBA to wait as a function of Mathcad state.

 

Regards,

Best answer by terryhendicott

Hi,

This is from the help files for the API and may be what you are after.

 

Object: Worksheet

Methods

DefaultCalculationTimeout(arg as integer)—Gets/Sets the DefaultCalculationTimeOut value of the worksheet. It defines the default time that the application waits for the engine to recalculate the whole document, and affects different types of Get/SetValue APIs except APIs whose time out is passed as a parameter.
arg is defined in seconds
0 means do not wait
–1 means wait no matter how long
The default time-out is 60 seconds

 

Cheers

 

2 replies

24-Ruby III
February 25, 2022

 Hi,

 

Please specify which version of Mathcad are you using?

21-Topaz II
February 26, 2022

Hi,

This is from the help files for the API and may be what you are after.

 

Object: Worksheet

Methods

DefaultCalculationTimeout(arg as integer)—Gets/Sets the DefaultCalculationTimeOut value of the worksheet. It defines the default time that the application waits for the engine to recalculate the whole document, and affects different types of Get/SetValue APIs except APIs whose time out is passed as a parameter.
arg is defined in seconds
0 means do not wait
–1 means wait no matter how long
The default time-out is 60 seconds

 

Cheers