【发布时间】:2021-12-14 15:17:29
【问题描述】:
应在代码中更改哪些内容(可在 www.extendoffice.com 找到)以将其限制为文本的选定部分(不适用于整个文档)。
代码正在从一个 Word 文档中提取超链接到另一个。
Sub HyperlinksExtract()
Dim oLink As Hyperlink
Dim docCurrent As Document 'current document
Dim docNew As Document 'new document
Dim rngStory As StoryRanges
Set docCurrent = ActiveDocument
Set docNew = Documents.Add
For Each oLink In docCurrent.Hyperlinks
oLink.range.Copy
docNew.Activate
Selection.Paste
Selection.TypeParagraph
Next
Set docNew = Nothing
Set docCurrent = Nothing
End Sub
【问题讨论】:
-
试试
Try For Each oLink In Selection.Hyperlinks,可能因为docNew.Activate而不起作用。你在docNew的哪个位置粘贴? -
不幸的是它不起作用。对于每个 oLink 在 Selection.Hyperlinks 中打开了新文档但为空。我只想以任何形式生成这些超链接的列表 - 现在它在新文档中,但也可以在 excel 中,甚至在与所选文本相同的文档中 - 只是为了在所选文本的末尾创建这些超链接的列表文本。
标签: vba ms-word hyperlink selection