问题描述
大家好,
我有一个问题是返回MS Word文档行的一部分。我用来搜索word doc内容的特定字符串是在:之后。
示例:
我在寻找什么for String1:这不是我想要在VB2010中返回的内容。
我正在寻找的是String2:这不是我想要在VB2010中返回的内容。
我正在寻找的是String3:这就是我想在VB2010中返回的内容。
我正在寻找的是String4:这不是我想要返回的内容VB2010。
我要找的是String5:这不是我想在VB2010中返回的内容。
搜索字符串是:String3 :
我尝试过:
Hello to all,
I have a problem to return a part of MS Word Document line. The specific string that I am using to search the content of word doc is after ":".
Example:
What I am looking for is String1: This is not what I want to return in VB2010.
What I am looking for is String2: This is not what I want to return in VB2010.
What I am looking for is String3: This is what I want to return in VB2010.
What I am looking for is String4: This is not what I want to return in VB2010.
What I am looking for is String5: This is not what I want to return in VB2010.
Search string is: String3:
What I have tried:
Dim findText As String = "String3:"
oWord.Selection.Find.ClearFormatting()
If oWord.Selection.Find.Execute(findText) = True Then
MessageBox.Show("Text found.")
'In the current line, how to return text after the found string?
Else
MessageBox.Show("The text could not be located.")
End If
非常感谢任何帮助。
Any help is very appreciated.
推荐答案
Dim TextToFind As String
TextToFind = "String3:"
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = TextToFind
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
找到标记后,需要找到文本的开头和结尾你想要合作。我有一些代码可以向您展示如何在Word文档中移动并选择文本: []功能。它不会完全符合您的要求,但会指向正确的方向。
Once you have found the marker, you need to find the beginning and end of the text that you want to work with. I have some code that can show you how to move around and select text in a Word Document: TryParseNumber[^] function. It won't do exactly what you want but will point you in the right direction.
这篇关于返回特定字符串后的MS word文档行的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!