DZiW (X) Ukraine English to Russian + ...
Dear colleagues, I got a task to check text for two-letter alliterations (marking them light-green) and here is a hurry-skurry yet working example: Code:
| Sub Alliterations()
N = ThisDocument.Words.Count: If N < 10 Then Exit Sub' if very s... See moreDear colleagues, I got a task to check text for two-letter alliterations (marking them light-green) and here is a hurry-skurry yet working example: Code:
| Sub Alliterations()
N = ThisDocument.Words.Count: If N < 10 Then Exit Sub' if very short, then over
On Error Resume Next 'safety
Application.ScreenUpdating = False 'speeding up a little
i = 1
With ThisDocument
Do 'MAIN LOOP
Do 'seek the FIRST 2-letter pair at the beginning of the word
was = UCase(Left(.Words(i), 2))
i = i + 1
Loop Until (i < N) And (Left(was, 1) Like "[A-ZА-Я]")
it = UCase(Left(.Words(i), 2)) 'get the NEXT 2-letters from the NEXT word
While (it = was) And (i < N) 'and mark all matches
.Words(i).Characters(1).Font.ColorIndex = wdBrightGreen
.Words(i).Characters(2).Font.ColorIndex = wdBrightGreen
'.UndoClear
i = i + 1
DoEvents 'check for Ctrl+ScrollLock
was = UCase(Left(.Words(i), 2))
Wend
'If Application.NumLock = True Then Exit Sub 'a terminator flag
If i Mod 100 = 0 Then Application.StatusBar = i & "/" & N - i: DoEvents
Loop Until i > = N
End With 'ThisDocument
Beep
MsgBox "Done"
End Sub |
|
The hardware is no issue--a Corei7 desktop with 8GB RAM running MS Word 2013 under W8.1 x64, with a peak load under 30% and no intense HDD activity. The document is a 25K-word DOCX (OOXML). I ran the script, which did some 5000 words promptly, then started to slow down on and off without apparent reasons, steadily taking about 20% CPU time. As far as neither old DOC, nor RTF type changed a thing, nor Affinity/Priority, I thought it was something to do with Undo (see remarked UndoClear), but seems a red-herring too. I tried other plain texts with the same result. Of course, the script is far from perfection and non-optimized, but I'm really missing something important... Any ideas? Even better, if you know a software to mark alliterations at the beginning) Thank you ▲ Collapse | | John Fossey Canada Local time: 04:59 Member (2008) French to English + ... |
Not a software but a regex? ((aa)[a-z]*\s(aa)[a-z]*)|((bb)[a-z]*\s(bb)[a-z]*) etc. Or: \b(\w)\1\w*\s(\w)\1\w* https://regex101.com/r/fDuRWj/1
[Edited at 2018-04-25 04:56 GMT] | | | Rolf Keller Germany Local time: 10:59 English to German
|
|
DZiW (X) Ukraine English to Russian + ... TOPIC STARTER
John, I know it works faster without DoEvents, but retains the same pattern--doing first ~5K words at ease and hobbling down, let alone it doesn't break/exit the subroutine using Ctrl+ScrLk, alas. Hans, it's interesting, yet seems MS Word uses some other RegEx, right? | | | | To report site rules violations or get help, contact a site moderator: You can also contact site staff by submitting a support request » WORD: Alliteration VBA script Anycount & Translation Office 3000 | Translation Office 3000
Translation Office 3000 is an advanced accounting tool for freelance translators and small agencies. TO3000 easily and seamlessly integrates with the business life of professional freelance translators.
More info » |
| Protemos translation business management system | Create your account in minutes, and start working! 3-month trial for agencies, and free for freelancers!
The system lets you keep client/vendor database, with contacts and rates, manage projects and assign jobs to vendors, issue invoices, track payments, store and manage project files, generate business reports on turnover profit per client/manager etc.
More info » |
|
| | | | X Sign in to your ProZ.com account... | | | | |
|