重复操作到文档的末尾 [英] Repeat Action to the end of a document
问题描述
我对IT世界很陌生。 我正在使用Word 2007中的VBA创建宏。 宏的目标是在整个文档中突出显示黄色的每一条第3行,无论是10行,10段还是10页
长。 我包含了迄今为止我在宏上录制的信息,这使得它突出显示第1行并跳过2行以进入第3行。 我正在寻找需要高于和低于指令
的信息,这将允许它在文档结束之前执行操作。
I am very new to the IT world. I am working with creating a macro using VBA in Word 2007. The objective of the macro is to highlight every 3rd line in yellow all the way through the document whether it is 10 lines, 10 paragraphs, or 10 pages long. I am including the information that I have recorded on the macro so far which has allowed it to highlight the 1st line and skip down 2 lines to get to the 3rd line. I am looking for the information that needs to go above and below the instructions that will allow it to perform the action until the end of a document.
我认为这是"Do..Loop Until< condition>"类型声明,但我不知道条件是什么,直到能够使其工作。 我猜这是一个非常入门级的编程问题但是我会很感激
任何帮助! 谢谢你的帮助!
I believe it is a "Do..Loop Until <condition>" type statement but I do not know what the condition is after until to be able to make it work. I am guessing that this is a very entry level type programming question but I would appreciate any assistance! Thank you for your help!
推荐答案
试试此版本:
Sub HighlightEvery3()
Dim lngLine As Long
Dim lngStart As Long
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Do
lngStart = Selection.Start
lngLine = lngLine + 1
If lngLine Mod 3 = 1 Then
ActiveDocument.Bookmarks("\line").Range.HighlightColorIndex = wdYellow
End If
Selection.MoveDown
Loop Until Selection.Start = lngStart
Application.ScreenUpdating = True
End Sub
这篇关于重复操作到文档的末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!