![]() |
#5
|
|||
|
|||
![]()
delboy,
Graham already knows this, but for the sake of completeness and for others looking to do something similar, I'm going to mention it. Graham is spot on about lines and pages being sort of an illusion in a Word document, but interestingly enough, in "Print Layout" view there are things called "PAGES, RECTANGLES AND LINES" that can be leveraged with VBA for useful things. Not to mention any names, but lets say we have an elderly, bumbling and forgetful politician giving a speech and we want to use a PC with an open Word document as his (or her) teleprompter. We want to avoid gaffs so we are going to automatically scroll through the document line by line highlighting the text and pausing for say half a second on each LINE. Code:
Option Explicit Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private bStop As Boolean Sub StopScroll() bStop = True End Sub Sub ScrollByLine() Dim oPage As Page Dim lngRec As Long, lngLine As Long Dim lngHLCI As Long Dim oRng As Word.Range bStop = False For Each oPage In ActiveDocument.ActiveWindow.ActivePane.Pages For lngRec = 1 To oPage.Rectangles.Count For lngLine = 1 To oPage.Rectangles(lngRec).Lines.Count lngHLCI = oPage.Rectangles(lngRec).Lines(lngLine).Range.HighlightColorIndex oPage.Rectangles(lngRec).Lines(lngLine).Range.Select Set oRng = Selection.Range oRng.Characters(1) = UCase(oRng.Characters(1)) Selection.Collapse wdCollapseEnd oRng.HighlightColorIndex = wdYellow Doze 500 'half second DoEvents ActiveDocument.ActiveWindow.SmallScroll Down:=1 'one line oRng.HighlightColorIndex = lngHLCI Application.ScreenRefresh If bStop Then GoTo lbl_Exit Next lngLine Next lngRec Next oPage lbl_Exit: Exit Sub End Sub Sub Doze(ByVal lngPeriod As Long) DoEvents Sleep lngPeriod End Sub Graham's code worked perfectly for you because your document is set up where each line is a separate paragraph. Had you used line breaks (Shift+Enter) to create new lines or if you have simply typed several lines of text and "still" wanted each of those lines capitalized, then by extension of what you have seen above, you could have used this: Code:
Sub CapFirstLine() Dim oPage As Page Dim lngRec As Long, lngLine As Long Dim lngHLCI As Long Dim oRng As Word.Range bStop = False For Each oPage In ActiveDocument.ActiveWindow.ActivePane.Pages For lngRec = 1 To oPage.Rectangles.Count For lngLine = 1 To oPage.Rectangles(lngRec).Lines.Count oPage.Rectangles(lngRec).Lines(lngLine).Range.Characters(1) = _ UCase(oPage.Rectangles(lngRec).Lines(lngLine).Range.Characters(1)) Next lngLine Next lngRec Next oPage lbl_Exit: Exit Sub End Sub Again, as Graham has pointed out, a CAP letter takes up more space than a lower case letter so the result of running that code on multi-line paragraphs could be disappointing. |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
jrhlavac | Word VBA | 1 | 10-08-2015 08:19 PM |
Create exceptions to the "Capitalize Each Word" command | TonyTyner@comcast.net | PowerPoint | 0 | 03-13-2015 09:13 AM |
Newbie - Need help with VBA code to capitalize last line of addresses | jjreg | Word VBA | 2 | 11-07-2014 10:19 PM |
![]() |
zulhfreelancer | Excel | 5 | 12-10-2012 07:51 AM |
capitalize first letter of sentences | norco1 | Word | 0 | 06-25-2006 12:37 PM |