Reputation: 1456
I am trying to change the number in my text box.
My code so far looks like this:
Sub Box()
ActiveSheet.Shapes("Asbuilt_Number1").Copy
ActiveSheet.Range("C25").PasteSpecial
Selection.ShapeRange.TextFrame.textRange.Characters.text = "2"
Selection.Name = "Asbuilt_Number"
End Sub
what is based from the Macro
Sub Boxes_Two()
'
' Macro3 Macro
'
'
ActiveSheet.Shapes.Range(Array("Asbuilt_Number_1")).Select
Selection.Copy
ActiveSheet.Paste
Selection.ShapeRange.IncrementLeft -0.75
Selection.ShapeRange.IncrementTop 347.25
Selection.ShapeRange(1).TextFrame2.textRange.Characters.text = "2"
With Selection.ShapeRange(1).TextFrame2.textRange.Characters(1, 1). _
ParagraphFormat
.FirstLineIndent = 0
.Alignment = msoAlignCenter
End With
With Selection.ShapeRange(1).TextFrame2.textRange.Characters(1, 1).Font
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 15
.Name = "+mn-lt"
End With
ActiveSheet.Shapes.Range(Array("Asbuilt_Number_1")).Select
Selection.ShapeRange.Name = "Asbuilt_Number"
Selection.Name = "Asbuilt_Number"
End Sub
I am unhappy with macro, since my copied number goes in completely different place, than I targeted.
My non-macro code throws error: Object doesn't support this property or method at the line
Selection.ShapeRange.TextFrame.textRange.Characters.text = "2"
Even if I remove the Characters
, likewise in the template below:
https://learn.microsoft.com/en-us/office/vba/api/project.shaperange.textframe2
How can I change the name of my textboxes swiftly?
Upvotes: 0
Views: 3034
Reputation: 1471
This works for me, let's try the following code:
Note: ActiveSheet.Range("C25").Paste
will not work
Sub Box()
With ActiveSheet
.Shapes("Asbuilt_Number1").Copy
[C25].Activate
.Paste
.Shapes(.Shapes.Count).Name = "Asbuilt_Number2"
.Shapes("Asbuilt_Number2").TextFrame2.TextRange.Characters.Text = "2"
End With
End Sub
Upvotes: 1