VBA Excel如何在文本框中编写Excel公式 [英] VBA Excel how to write Excel formula in the textbox

查看:275
本文介绍了VBA Excel如何在文本框中编写Excel公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将Excel公式放入文本框?

How can I put the Excel formula into the textbox?

我尝试过这样的事情:

 Sub CivBox()
  With ActiveSheet
   .Shapes("Civils 3").Copy
   [C26].Activate
   .Paste
   .Shapes(.Shapes.Count).Name = "Civils 4"
   .Shapes("Civils 4").TextFrame2.TextRange.Characters.Text = "=D51"
 End With
End Sub

但是唯一的字符串被返回

But the only the string is returned

是否可以将Excel公式放入文本框中,还是应该先在某个单元格中准备它,然后将该单元格作为范围链接到此文本框中?

Is it possible to put the Excel formula into the textBox or shall I prepare it in some cell first, and next link this cell into this textbox as a range?

推荐答案

如果您使用的是Shape,则可以使用此

If you're using a Shape you could use this

Sub x()

ActiveSheet.Shapes(1).OLEFormat.Object.Formula = "=A1"

End Sub

对于文本框,您可以使用

For a textbox you can use

ActiveSheet.TextBoxes("TextBox 1").Formula = "=A1"

这篇关于VBA Excel如何在文本框中编写Excel公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆