简体   繁体   中英

VBA Excel how to write Excel formula in the textbox

How can I put the Excel formula into the textbox?

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?


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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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