I have a fairly simple excel vba script to generate word documents from individual page templates. It's just a glorified search and replace to substitute template keys for cell values.
When I try and copy a multiline cell into word, or insert a vbCr or vbNewLine using the method:
strReplace = TagArray(i, j)
strReplace = Replace(strReplace, Chr(10), vbCr)
strReplace = Replace(strReplace, vbNewLine, vbCr)
It just shows up in word as a ascii box character. If I just let Chr(10) or Chr(10) Chr(13) go through, word discards it and has no line breaks.
How the heck do I preserve the multiline cell?
Couldn't figure it out, so I borrowed the technique from here:
Generate Word Documents (in Excel VBA) from a series of Document Templates
and got rid of the Replace() and changed it too:
'Iterate through all of the keys to be replaced
For j = 0 To KeyCount - 1
strReplace = TagArray(i, j)
clipBoard.SetText IIf(strReplace = vbNullString, "", strReplace)
clipBoard.PutInClipboard
For Each storyRange In OutputDoc.StoryRanges
Do
With storyRange.Find
.MatchWildcards = True
.Text = KeyArray(j)
.Replacement.Text = "^c"
'.Replacement.Text = strReplace
.Execute Replace:=2
End With
Set storyRange = storyRange.NextStoryRange
Loop While Not storyRange Is Nothing
Next
Next j
Next i