dimanche 1 mars 2015

VBA How to pass formatted text from Excel to MS Word

I've requirement where in I need to compare two samples of text in Excel using VBA. Since each text sample is more than 3000 characters in LEN, I use a Userform.TextBox field fetch,storing them into string variables.


Next, I use a VBA code that I found here by 'mikerickson': VBA routine to comp


To compare the texts. The problem is that the output of this code is input into a Cell: A1. Since the text samples contain more than 3000 characters each, the result is not displayed in A1 since excel has limit on the number of characters per cell.


I would like to know how to get the result (with all the formatting like underline and strikethrough) in to an MS Word Doc.


Currently, this is the code used to output to cell A1.



strResult = ComparedText(strOne, strTwo, olStart, olLength, nwStart, nwLength)

With outCell.Cells(1, 1)
.Clear
.Value = strResult
For i = LBound(olStart) To UBound(olStart)
If olStart(i) <> 0 Then

With .Characters(olStart(i), olLength(i)).Font
.ColorIndex = 3
.StrikeThrough = True
End With
End If
Next i
For i = LBound(nwStart) To UBound(nwStart)
If nwStart(i) <> 0 Then
With .Characters(nwStart(i), nwLength(i)).Font
.ColorIndex = 4
.Underline = True
End With
End If
Next i
End With


Need a replacement code here which will enter strResult into a word document with the exact same formatting for the mismatches as in the code above.


Hoping somebody helps. Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire