Consulting

Results 1 to 2 of 2

Thread: Convert Word document comments to Markdown-formatted links

  1. #1
    VBAX Newbie
    Joined
    Dec 2022
    Location
    Paris, France
    Posts
    1
    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]

Posting Permissions

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