vba中excel的application.evaluate命令出现问题
我的一些 Excel 代码有问题,我无法理解。
好的,我在 excel vba、office 2007 中使用 application.evaluate 命令。
如果我有 Evaluate("SIN(45)")
它会返回一个很好的预测数字。但是,如果我执行 Evaluate("eq")
代码就会崩溃。
eq 是我从 Excel 中读入的方程。等式为:3*x^2+5*x+1
。它作为字符串传入。为了确保发生这种情况,我将其放置在另一个定义为字符串的变量中。我使用 Excel 的替换函数替换了方程中的 x。 equation = Replace(equation, "x", temp)
。
然而,当我进行评估时,代码崩溃了,我不知道为什么。 总计 = 总计 + 评估(“方程”)
。非常感谢任何帮助
I have a problem with some excel code that I am having trouble getting my head around.
Okay so I am using the application.evaluate command in excel vba, office 2007.
If i have Evaluate("SIN(45)")
it returns a nice predicted number. However if I do Evaluate("eq")
the code crashes.
eq is an equation i am reading in from excel. the equation is: 3*x^2+5*x+1
. It is passed in as a string. to make sure this happened I placed it in another variable that I had defined as a string. I replace the x's in the equation using excel's replace function. equation = Replace(equation, "x", temp)
.
However, when i get to the evaluate the code breaks down and I am not sure why. Total = Total + Evaluate("equation")
. Any help is greatly appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题在于您引用字符串“方程”而不是方程字符串。
我会做
Evaluate(equation)
或Evaluate(Replace(equation, "x", temp))
相反,请注意方程周围不带引号 ",这将产生有效的答案。希望这会有所帮助。
I think the problem lies where you references a string "equation" instead of the equation string.
I would do
Evaluate(equation)
orEvaluate(Replace(equation, "x", temp))
instead, note without the quotations " around equation and that would yield a valid answer.Hope this help.