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 to that point. If I use "ActiveWindow.ActivePane.Close" to close the comments pane, the cursor still remains wherever it was in the document. This causes problems when I insert the link text + link URL, as it's in the wrong place.
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...
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 to that point. If I use "ActiveWindow.ActivePane.Close" to close the comments pane, the cursor still remains wherever it was in the document. This causes problems when I insert the link text + link URL, as it's in the wrong place.
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...