简体   繁体   English

VBA Excel如何在文本框中编写Excel公式

[英]VBA Excel how to write Excel formula in the textbox

How can I put the Excel formula into the textbox?如何将Excel公式放入文本框?

I tried sth like this:我试过这样的:

 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但返回的只是字符串

在此处输入图片说明

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?是否可以将 Excel 公式放入文本框,或者我应该先在某个单元格中准备它,然后将此单元格作为范围链接到此文本框?


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"

You can do this indirectly.你可以间接地做到这一点。 You can't put it IN the box, but you can select the textbox (not the contents of the textbox), go to the formula bar, and reference a cell.你不能把它放在框中,但你可以选择文本框(不是文本框的内容),转到编辑栏,并引用一个单元格。

Edit: This might help: https://www.solveyourtech.com/how-to-display-a-formula-result-in-a-text-box-in-excel-2010/编辑:这可能有帮助: https : //www.solveyourtech.com/how-to-display-a-formula-result-in-a-text-box-in-excel-2010/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM