[英]Get the last line of any word document using macros VBA
I have lots of word documents to rename using the lastline of the document.我有很多 Word 文档要使用文档的最后一行重命名。 The lastline of the document starts with: "Expediente N°", so this is how I've tried to solve the problem unsuccessfully.文档的最后一行以“Expediente N°”开头,所以这就是我尝试解决问题的方式,但没有成功。
With Selection.Find
.Text = "Expediente N° "
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
MsgBox Selection.Text
Remember that the last line could be dinamically, for example "Expediente N° 334234" or "Expediente N° 1111", that why I think the solution in get the entire last line of the document.请记住,最后一行可能是动态的,例如“Expediente N° 334234”或“Expediente N° 1111”,这就是为什么我认为解决方案是获取文档的整个最后一行。
Some times, after writing a paragraph, you may press Enter (even more times).有时,在写完一段之后,您可能会按 Enter(甚至更多次)。 The next code will return the last paragraph text, above such a end line character:下一个代码将返回最后一段文本,在这样的结束行字符上方:
Sub testLastParagraphText()
Dim p As Paragraph
Set p = ActiveDocument.Paragraphs.Last
Do While p.Range.Text = Chr(13)
Set p = p.Previous
Loop
Debug.Print p.Range.Text
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.