It is really impossible to append more than 255 chars into a single cell by VBA macro in MS Excel?
Sample code:
Option Explicit
Sub TestSub()
Dim L As Long
' Const str = "1" & vbLf
Dim i As Integer
Range("A1").ClearContents
Range("A1").WrapText = True
For i = 1 To 260 ' any number greatest than 255
L = Range("A1").Characters.Count
Debug.Print L
Range("A1").Characters(L + 1, 1).Insert ("A")
Next i
End Sub
Added: It is important to save previous formatting of chars in cell.
The following code will write 500
A
into cellA1
. Afterwards, every otherA
will be formatted bold.I hope that solves your problem.
Note: your code won't work because you are trying to insert a character after
L + 1
. Yet, your string is currently onlyL
long and notL + 1
. Once you have inserted anotherA
you will haveL + 1
characters in that cell. But not yet. So, if you are using your code withRange("A1").Characters(L, 1).Insert ("A")
then it will work.Edit#1:
The following code has been tested and correctly inserts 500
A
into cellA1
. Furthermore, some of theA
will be formatted bold.I think that this is due to Excel. Mr. Microsoft : "If you use a Microsoft Visual Basic for Applications procedure to pass a string that is greater than 255 characters in length to an object, such as a text box, Microsoft Excel may truncate the string to 255 characters or may fail to enter the string in the text box. "
Even though you are not passing a more than 255 characters string, I think this is related
https://support.microsoft.com/en-us/kb/213841
They offer a workaround on that support page.
question changed with this additional comment
https://stackoverflow.com/users/4742533/stayathome
will return and update this
initial answer
You can format the partial string using characters.
Code below appends your sample string to test string (300 characters long), then makes the last three italic, the three before that bold.