Query on Word VBA - Comments.Range.Text extracting comments from a document and preserving formatting

oitbc

New Member
Joined
Mar 11, 2019
Messages
14
Hi All,

I've got a macro I have updated, based on some work from the past. It now sends the comments to Excel. The thing I noticed is that in using the Comments.Range.Text to get a copy of the comment, any formatting that was applied in the Comment is removed. This does not happen if I write the comment to a word table, only when I do it to a Excel cell.

For example:

If the comment says

"This isn't great, we need to repeat the newline and then make sure we display some numbered lists in it.

There is the newline above here

1. Item 1
2. Item 2"

it gets returned as a stream of

"This isn't great, we need to repeat the newline and then some numbered lists in it.There is the newlineItem 1Item 2"

when called by

VBA Code:
Celltofill = oDoc.Comments(n).Range.Text
and n is just a counter for a for loop

Any idea how to preserve the formatting?
 
Last edited:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Sorry, I should say that when I use the following code

VBA Code:
Dim oTable As Table
For n = 1 To nCount
With oTable.Rows(n + 1)
'The text of the comment
.Cells(7).Range.Text = oDoc.Comments(n).Range.Text
in Word with a table then it does still remove the numbers, but does keep the newlines, so it looks like this in Word

"This isn't great, we need to repeat the newline and then make sure we display some numbered lists in it.

There is the newline above here

Item 1
Item 2"
 
Upvote 0
Solved it myself sorry

VBA Code:
Replace(oDoc.Comments(n).Range.Text, vbCr, Chr(10))
 
Upvote 0

Forum statistics

Threads
1,214,647
Messages
6,120,722
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top