Consulting

Results 1 to 3 of 3

Thread: Convert Word document comments to Markdown-formatted links

  1. #1
    VBAX Newbie
    Joined
    Dec 2022
    Location
    Paris, France
    Posts
    2
    Location

    Convert Word document comments to Markdown-formatted links

    Hi all. I run an editorial website that uses the Markdown formatting language within the CMS. For example, [this is a hyperlink](https://link.url). We get perhaps half of the articles we publish as Word documents, and links come in a range of formats -- classic hyperlinks, but also footnotes, endnotes, and comments. I have written macros that very capably convert the first three cases to Markdown-formatted links within the text, but am having trouble with converting comments that contain URLs to Markdown links.

    Below is a mix of code and pseudocode to give you an idea of what I'm looking for:

    ' switch links comments to text if there's an http within
    For Each oComment In ActiveDocument.Comments
         If InStr(oComment.Range.Text, cHttp) > 1 Or Left(oComment.Range.Text, 4) = cHttp Then 
             {select the text that was commented; we should be in the document text itself, not the comments}
             Selection.TypeText "[" & Selection.Text & "](" & oComment.Range.Text & ")"
         End If
    oComment.Delete
    Next
    Aspects of the above work, but I run into problems with selecting the actual text, not the comment. For example, "oComment.Range.Select" will highlight where the comment is in the document, but doesn't actually move the cursor. If I use "ActiveWindow.ActivePane.Close" to close the comments pane, the cursor still remains wherever it was in the document.

    Thanks for any suggestions you might have. I'm sure that I'm just missing a single line or two of code. Endless Internet searches haven't revealed much, so here I am. Fingers crossed...
    Last edited by Aussiebear; 12-13-2022 at 09:28 AM. Reason: Added code tags to supplied code

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Newbie
    Joined
    Dec 2022
    Location
    Paris, France
    Posts
    2
    Location
    Update: I've mostly succeeded in extracting URLs from comments. However, I now have a two-level challenge -- footnotes/endnotes that have hyperlinked text within them. I can extract the text of the reference, but I lose the link URL. I can convert all hyperlinks in the document to Markdown, but those in foot/endnotes are ignored. Bottom line, what I would like is to get all reference URLs out of wherever they are (footnote, endnote, comment) and in whatever form (bare URLs or hyperlinks) and convert them to Markdown in the document body. Thanks in advance for any suggestions that anyone might have. .
    Last edited by Leighton; 10-04-2023 at 12:51 AM. Reason: clarification

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •