none
VBA to get HTML Formatted String with Contents of a Table Cell RRS feed

  • Question

  • Is there a way to programmatically (in VBA) create a string with HTML tags that represents the contents of a table cell?  For example, if the cell contains:

    Example 1:

    • List item 1
    • List item 2

    I would like to generate a string containing:

           <b><u>Example 1:</u></b><br><br><ul><li>List item 1</li><li>List item 2</li></ul>

    I have tried things like the following without any success:

    docNew.Tables(intTableCount).Cell(intRowCount, 2).Range.TextRetrievalMode.ViewType = wdMasterView
    docNew.Tables(intTableCount).Cell(intRowCount, 2).Range.TextRetrievalMode.IncludeFieldCodes = True
    docNew.Tables(intTableCount).Cell(intRowCount, 2).Range.TextRetrievalMode.IncludeHiddenText = True
    docNew.Tables(intTableCount).Cell(intRowCount, 2).Text
    

    Suggestions?

    Thanks!

    Don

    Friday, March 25, 2011 3:10 PM

Answers

  • AFAIK to get the HTML you would either have to

     a. copy the contents to the clipboard, then get the HTML from the clipboard or

     b. use selection.Range.ExportFragment, specifying a suitable HTML format, to export to a file, then re-read that file to get the HTML. Not sure which versions of Word ExportFragment is available in.


    Peter Jamieson
    Friday, March 25, 2011 4:07 PM
  • Peter,

    Ended up going with option B.  While not terribly elegant or efficient, it got the job done.

    Thanks!

    Don

    Monday, March 28, 2011 6:05 PM

All replies

  • AFAIK to get the HTML you would either have to

     a. copy the contents to the clipboard, then get the HTML from the clipboard or

     b. use selection.Range.ExportFragment, specifying a suitable HTML format, to export to a file, then re-read that file to get the HTML. Not sure which versions of Word ExportFragment is available in.


    Peter Jamieson
    Friday, March 25, 2011 4:07 PM
  • Peter,

    Ended up going with option B.  While not terribly elegant or efficient, it got the job done.

    Thanks!

    Don

    Monday, March 28, 2011 6:05 PM
  • Glad something worked, and thanks for the feedback!


    Peter Jamieson
    Monday, March 28, 2011 7:02 PM