VBA Excel how to write Excel formula in the textbox

Mariusz Krukar :

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

enter image description here

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?


SJR :

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"

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=383183&siteId=1