79626922

Date: 2025-05-17 19:33:01
Score: 0.5
Natty:
Report link

The Alternative Approach described above takes advantage of the widely accepted capabilities of Word Compare. it is not fast but gives very good results. So, to save execution time, you would have Excel directly handle the simple cases (one input cell is empty or both cells are equal), and use Word Compare only when necessary.

However, you need to be careful with control characters, particularly linefeed Chr(10). When the macro copy/pastes the comparison redline results from Word into Excel, if that redline text contains any linefeeds, this will cause the target cell in Excel to split into additional rows at each linefeed. My workaround is to have Excel replace all the Chr(10) linefeed characters in both input strings with something innocuous (like the pilcrow). This does not affect Word's redline generation, and the resulting string from Word will paste into Excel without causing cell splitting. If you are okay with the redlines containing the substitute character (pilcrow) instead of actual line feeds, you're done.

But if you want the redlines to display with real linefeeds, it gets more complicated. You will want to remove all deleted linefeeds (or pilcrow substitute) because although marked as deleted, a linefeed character would still cause a line feed to occur in the displayed text. After the paste into Excel, you would replace the pilcrows with Chr(10). Be careful doing character replacements because using string functions will affect the character-level formatting we have worked so hard to generate. You may need to operate on individual Characters and their Font properties. Just beware.

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: tbg22