CopyToClipBoardAsHTML error in Word


I get an issue when I copy a TAdvStringGrid to clipboard with CopyToClipBoardAsHTML method and paste it into a Word document with OLE's paste method.

I already had this issue here , I tought it was resolved but it seems not in all cases.

You have a screenhot of my Word document (*.docx) with 2 tables:

  • one table is correct: it has been created with OLE commands

  • the other is the HTML code: it came from a TAdvStringgrid, CopyToClipBoardAsHTML command and OLE's Paste.


We will need more info how to reproduce this.

Test code:

procedure TForm1.Button1Click(Sender: TObject);


Thank you. I still have randomly the issue.

Do you want this Word document ?


To try to investigate this, we would need a sample source project that has all the grid settings for which a copy to clipboard will fail when pasting in MS Word.

I cannot send you a sample source project because of datas, types...

Here is a file containing Grid settings and events, I hope it can be helpful


Can't you call Grid.SaveToFile()? Or is the data included confidential - which often is the case. However, a binary file with data and all settings actually would recreate your use case.

Did you at least fill this particular grid with some data and check if copy & paste to MS Word will indeed show the error?
If so, please provide at least also some data so that we can see the issue & investigate.

Previous file is only containing grid design's properties.

  • File "Grid_HTML_data.txt" is containing the ouput result in Word document
  • File "AdvTabSynthese_SaveToFile" is the resulting from AdvTabSynthese.SaveToFile when the output is wrong.

As I explained, this issue is random.


Based on the information you provide, this cannot be reproduced.
You find the test project here that we created after doing all efforts to bring together your partial information provided. (53.9 KB)

Good morning,

I modified your project to reproduce the issue.


I can reproduce this now in something like 25% of runs.
I could not find anything related to TAdvStringGrid itself that could be the cause of this particular problem. The content of the clipboard at the time it fails is 100% identical with the content of the clipboard at other times. The first indication from this problem is that this is rather an instability in MS Word and clipboard retrieval. A suggestion is to try to put a delay between the command to copy to clipboard and the MS Word OLE command to paste from clipboard.

I put a delay and tried a lot, I cannot have the issue anymore.

Thank you for your support



I made some additional tests and have an issue with the last row of a grid when I copied it to Word: it misses some informations and frames:

Grid in project:

Grid in Word docX after CopyToClipBoardAsHTML

You can check it with following project:

If I add an empty row at the end, everything is fine.



Could you have any infos about this issue ?

I installed TMSVCLUIPackSetupReg v10.4.3.0 and I still have the issue.


We did not do any changes.
As I stated, we verified this and the HTML produced and placed on the clipboard is in all cases 100% identical. The problem must be in MS Word itself, most likely it looks like a timing issue there.

Hello Bruno,

Thank you for the answer.

I completed this thread with another issue: I made some additional tests and have an issue with the last row of a grid when I copied it to Word: it misses some informations.

You can recreate the bug with attached project

Maybe do you want I creat a new thread ?

Hello Bruno,

Regarding to my 2nd issue, the html file is correct but the ole paste method removes the last cell.

To solve this, I save the advGrid to html file and insert it into the Word file with ole command.

Thank you for your help

This appeared to be a MS Word specific interpretation of the HTML fragment on the clipboard (It works fine in Google Docs, Excel, Google Sheets).
We have adapted the code to make it compatible with how MS Word treats this and this fix will be included in the next update.