#1
|
|||
|
|||
Word VBA Help
Hi All,
I'm a very noob user when it comes to word macros/VBA so I hope someone could help me without it being too much trouble. I need a macro that will highlight every 3rd line throughout a word document. Also if it could prompt the user to start from the beginning of the document or start from where the cursor is. I really have no idea where to start with this and I'm hoping for some help with this if possible. |
#2
|
||||
|
||||
Danny
This sounds a lot like a learning task assigned by a teacher so I don't want to just give you the answer. The first thing to discuss is the fact that 'line' is not a good term to use since it is not a fixed or easily testable thing in Word. You should be working with 'paragraphs' instead of 'lines'. To get started, try recording a macro of you applying highlighting to a selected paragraph of text. Once you have that minimal code, post it here and we can point you to how to start performing the other steps.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Danny,
I'm not going to give you the whole fish and this is a bit clunky, but you can use selection and the wdLine unit to get this started: Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim oRng As Range Dim lngCount As Long Dim bExit As Boolean Set oRng = ActiveDocument.Range oRng.Collapse wdCollapseStart Application.ScreenUpdating = False oRng.Select On Error GoTo Err_Exit Selection.MoveDown wdLine, 2 Selection.Bookmarks("\line").Select Selection.Range.HighlightColorIndex = wdBrightGreen Selection.Collapse wdCollapseEnd Do lngCount = 0 Do Selection.MoveDown wdLine, 1 lngCount = lngCount + 1 Selection.Bookmarks("\line").Select If Selection.Range.End + 1 = ActiveDocument.Range.End Then bExit = True If bExit Then Exit Do Loop If lngCount = 2 Then Selection.Range.HighlightColorIndex = wdBrightGreen Selection.Collapse wdCollapseEnd End If If bExit Then Exit Do Loop lbl_Exit: Application.ScreenUpdating = True Exit Sub Err_Exit: Resume lbl_Exit End Sub |
Thread Tools | |
Display Modes | |
|