I have an excel program that allows users to add a row or delete a row in excel, then the following code to add text to the shape on the page, which corresponds to the numbers input into the rows:
Function AddTextToShape(shp As Shape, _
sText As String, _
Optional bAppend As Boolean = False) As Boolean
' Adds or appends text to a shape
Dim i As Long
Dim iBeg As Long
TextBox1.MultiLine = True
On Error GoTo Oops
With shp.TextFrame
If bAppend Then
iBeg = .Characters.Count
Else
.Characters.Text = vbNullString
End If
For i = 1 To Len(sText) Step 255
.Characters(iBeg + i).Text = Mid(sText, i, 255)
Next i
End With
AddTextToShape = True
End Function
Sub GenerateReport_Click()
a = "Cognitive Processing Ability: Cognitive, or mental, processes " + vbNewLine + vbNewLine
b = "Crystallized Intelligence (Gc): Crystallized Intelligence "
c = Range("STUDENTNAME") + "'s performance on the measures of Crystallized Intelligence fell within the " + Range("GCD") + " range (SS= "
d = Range("GCSS")
e = "; PR= "
f = Range("GCPR")
g = "), which suggests that these skills " + Range("GCF") + " " + Range("SMALLHIM") + " learning and performance. "
If Range("GCF") = "inhibit" Then
Ga = Range("STUDENTNAME") + " may benefit from increased exposure to environments rich in language that would provide new and varying experiences."
End If
ActiveSheet.Shapes("Report").TextFrame.Characters.Text = a & b & c & d & e & f & g & Ga
When I don't add or delete rows this code works, however, when a row is added or deleted I get the 1004 error: unable to set the text property of the characters class.
What am I missing? This is driving me crazy!
Bookmarks