vba - 如何在Word文档中快速查找和复制包含特定文本的段落?(或者,在Word文档中留下包含特定文本的段落?)
问题描述
我想在 Word VBA 中编写一个代码来快速查找和复制 Word 文档中包含特定文本的段落(或者,在 Word 文档中留下包含特定文本的段落),但有一行不完整。这是与我的问题非常相似的代码,但我想剪切/添加段落而不是删除它们,有没有人知道如何编写它?提前谢谢了!
解决方案
我更改了一条线以剪切并将所选段落添加到尖峰(我不知道它存在!)
然而,是/否消息框的存在并不能真正让您查看该段落,但希望它对您有用。
Sub SpikeParagraphsContainingSpecificTexts()
Dim strFindTexts As String
Dim strButtonValue As String
Dim nSplitItem As Long
Dim objDoc As Document
strFindTexts = InputBox("Enter text strings to be found here, and use commas to separate them: ", "Text strings to be found")
nSplitItem = UBound(Split(strFindTexts, ","))
With Selection
.HomeKey Unit:=wdStory
' Find the entered texts one by one.
For nSplitItem = 0 To nSplitItem
With Selection.Find
.ClearFormatting
.Text = Split(strFindTexts, ",")(nSplitItem)
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWholeWord = False
.MatchCase = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchAllWordForms = False
.Execute
End With
Do While .Find.Found = True
' Expand the selection to the entire paragraph.
Selection.Expand Unit:=wdParagraph
strButtonValue = MsgBox("Click yes to cut/spike graf, no to do nothing", vbYesNo)
If strButtonValue = vbYes Then
NormalTemplate.AutoTextEntries.AppendToSpike Range:=Selection.Range
End If
.Collapse wdCollapseEnd
.Find.Execute
Loop
Next
End With
MsgBox ("Word has finished finding all entered text strings.")
Set objDoc = Nothing
End Sub
希望能帮助到你。
推荐阅读
- java - 将我的数据从 firebase 数据库添加到我的列表视图时遇到问题
- android - 尝试创建 SDKNativeEngine 的新实例时出错
- verilog - SystemVerilog 的 Verilog 包装器
- java - 函数未进入循环
- python - 如何使用 Stripe Checkout 实施双面推荐计划?
- sql - 如何计算以月为单位的差异 SQL DB2
- android - Android studio在导航组件中构建错误,动作不是抽象的并且没有实现抽象成员actionID
- c++ - SDL 2 中带有不透明元素的完全透明窗口
- javascript - JavaScript,HTML 搜索引擎 - 如何获取元素的父级?
- cuda - CUDA 驱动 API 等效于 cudaDeviceSetCacheConfig