PDA

View Full Version : speed reading macro



sakkas
11-23-2008, 05:29 AM
Hi,

I would like to make a speed reading macro but I haven't programmed for ages and just can't get started. Basically this macro would just highlight a set number of words and run through the document this way.

the technical difficulty would reside in the fact that it can only highlight words on the same line so if, say, towards the end of the line, it is supposed to highlight 5 words but there are only 4 left, it should NOT highlight the first word of the next line. Yet there is no carriage return at the end of most lines...


Just an example of what I'm looking for (with 5 words):

1:
The most important thing about speed dating is the speed. Indeed speaking
in a high speed, high pitch voice is the best strategy you can adopt.

2:
The most important thing about speed dating is the speed. Indeed speaking
in a high speed, high pitch voice is the best strategy you can adopt.

3:
The most important thing about speed dating is the speed. Indeed speaking
in a high speed, high pitch voice is the best strategy you can adopt.

4:
The most important thing about speed dating is the speed. Indeed speaking
in a high speed, high pitch voice is the best strategy you can adopt.

5:
The most important thing about speed dating is the speed. Indeed speaking
in a high speed, high pitch voice is the best strategy you can adopt.

6:
The most important thing about speed dating is the speed. Indeed speaking
in a high speed, high pitch voice is the best strategy you can adopt.

Any ideas? Help would be very appreciated.

Thanks!

fumei
11-24-2008, 03:18 PM
Oh boy, you have problems.

I can not see how I, at least, can help at this point. Your example confused me. The bolded words...where do they come from? Why those ones? What criteria?

If I understand correctly....

The most important thing about speed dating is the speed. Indeed speaking
in a high speed, high pitch voice is the best strategy you can adopt.

Is OK because that string ("pitch voice is the best") is on ONE "line".

So....if it was not....then it would be:

The most important thing about speed dating is the speed. Indeed speaking
in a high speed, high pitch voice is the
best strategy you can adopt.

If this is the case, AND the actual strings are in an array of some sort, you could do it. It would not be trivial, but it is do-able.

I think.

Part of the problem is that these are paragraphs - there is no paragraph mark at the end of the
line", so you have to be able to get line numbers out. Which you can do. Here is ONE way. essentially, you do the search for the string, in the attached demo case i am using "Indeed speaking in a high" - 5 words.

In order to get a variation so that string is NOT on the same line, I had to restructure the paragraph margins. Otherwise, as the paragraphs have the same text, they will have the same ending point per line...yes? So, for the demo, I changed the paragraph margins.

This would be different - and not needed - if you are doing different search strings...obviously. Here is the demo doc code:Option Explicit

Sub yadda2()
Dim r As Range
Dim OtherRange_A As Range
Dim OtherRange_B As Range
Dim rStart As Long
Dim rEnd As Long

Set r = ActiveDocument.Range
With r.Find
Do While .Execute(FindText:="Indeed speaking in a high", _
Forward:=True) = True

rStart = r.Start
rEnd = r.End

Set OtherRange_A = ActiveDocument _
.Range(Start:=rStart, End:=r.Start)

Set OtherRange_B = ActiveDocument _
.Range(Start:=rEnd, End:=r.End)

If OtherRange_A.Information(wdFirstCharacterLineNumber) < _
OtherRange_B.Information(wdFirstCharacterLineNumber) Then
' no way Jose, more than one line
' but just to show it HAS been found
' let's turn it pink
r.HighlightColorIndex = wdPink
Else
r.HighlightColorIndex = wdBrightGreen
End If
Loop
End With

End SubTo get line information, you need a Range (or a Selection) object. The issue though, is that you need a separate object for the start of the found string (which is its own range), and the end of the found string. That is why there are two separate "locator" range objects.

Range.Information is a property of the range object itself(natch). In other words, you can NOT get wdFirstCharacterLineNumber from both the .Start and .End of any given Range.

.Start does not have the information, the RANGE object has the information. Thus, creating separate range objects for both the Start and End, and getting the Information from them.

If one is greater than the other, then logically, the other must be on a different line.

In the demo attached - click "Yadda Yadda" on the top toolbar - just to demonstrate that the code DOES find the search string "Indeed speaking in a high" (in all cases), the ones found but are on different lines are colored pink. The one found on ONE line is colored bright green.

fumei
11-24-2008, 03:21 PM
Sorry, I forgot you want to truncate the action. You still want the action, but only for the part on the line the start of the search string is on.

Darn.

You got problems. Still, it IS possible, but it would require some convoluted logic determination. I am not going to do it. But I can say that it can be done.

Seems rather odd to want to though.