在脚注文本上运行VBA
问题描述:
我是VBA的新手,并设法将一个简单的宏组合成一个将所有文本转换为超链接(粘贴在下面)的简单宏,我真的很喜欢它做同样的事情所有的脚注文本也是如此,但是我尝试过的在线答案都没有发挥作用。在脚注文本上运行VBA
有什么想法?
Sub FindLinkStyle()
Dim strStyle As String
strStyle = "Subtle Reference"
Selection.HomeKey Unit:=wdStory
With Selection.Find
.text = ""
.ClearFormatting
.Style = strStyle
Do While .Execute
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
Address:="#link"
Selection.Style = ActiveDocument.Styles("Normal")
Loop
End With
End Sub
答
不像字UI,“查找”只在您指定的“故事”的作品。所以在你的情况下,这取决于Selection
的位置。要具体说明脚注,请参阅以下代码示例中Range对象如何设置为“脚注故事”,然后查看Find中使用的范围。
Sub FindInFootnote()
Dim rngFT As word.Range
Set rngFT = ActiveDocument.StoryRanges(wdFootnotesStory)
With rngFT.Find
.Text = ""
.Style = "Subtle Reference"
.Replacement.Text = "XXXXX!!!!!"
.Execute Replace:=wdReplaceAll
End With
End Sub