vkhu
01-17-2018, 02:50 AM
Hi, I'm making a macro in word that will skip ahead a certain amount of words, then mark the place so I'll know where each section ends. The code is like so:
Sub QuotaWordHighlight()
On Error GoTo ErrorReport
' Cancel macro when no word is defined
Dim NoWord As Integer
' The number of word to jump
Dim NoWord2 As Integer
' The number of word to jump
Dim Msg As String
' This is what to display on the dialog box
PlayTheSound "W21 - Go Ahead TACCOM.wav"
Msg = "How many words do you want to do first?"
NoWord = InputBox(Msg)
Msg = "And then?"
NoWord2 = InputBox(Msg)
' How the variables are defined
Application.DisplayAlerts = False
PlayTheSound "W22 - Confirmed.wav"
Do Until ActiveDocument.Bookmarks("\Sel").Range.End = ActiveDocument.Bookmarks("\EndOfDoc").Range.End
Selection.MoveRight Unit:=wdWord, Count:=NoWord + 1
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Color = RGB(0, 60, 179)
Selection.MoveRight Unit:=wdWord, Count:=NoWord2 + 1
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Color = RGB(0, 60, 179)
Loop
' Searching the remaning (till the end of document)
PlayTheSound "W23 - Target Designated.wav"
ErrorReport:
End Sub
The problem is every single special character or number is recognized as a separate word. This means if, for example, I tell it to mark ahead every 50 words, sometimes I'll get a section with 41, sometimes 37, sometimes 46, and so on.
Is there a way to specify that if encounter such and such word, add 1 to the word count ("NoWord" and "NoWord2") and keep going?
EDIT: for those who are curious, this macro is to help me mark my translation quota each day. Say I plan to do 2,000 words a day, I would input "2000" into the text box (the text box will ask me twice about the number of words because sometimes my schedule force me to alternate my quota, such as 1,500 and 2,000 words each day, alternately), and every 2,000 words, there will be a part with blue letters, telling me once I've done translating up to that point, I can stop for the day.
Sub QuotaWordHighlight()
On Error GoTo ErrorReport
' Cancel macro when no word is defined
Dim NoWord As Integer
' The number of word to jump
Dim NoWord2 As Integer
' The number of word to jump
Dim Msg As String
' This is what to display on the dialog box
PlayTheSound "W21 - Go Ahead TACCOM.wav"
Msg = "How many words do you want to do first?"
NoWord = InputBox(Msg)
Msg = "And then?"
NoWord2 = InputBox(Msg)
' How the variables are defined
Application.DisplayAlerts = False
PlayTheSound "W22 - Confirmed.wav"
Do Until ActiveDocument.Bookmarks("\Sel").Range.End = ActiveDocument.Bookmarks("\EndOfDoc").Range.End
Selection.MoveRight Unit:=wdWord, Count:=NoWord + 1
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Color = RGB(0, 60, 179)
Selection.MoveRight Unit:=wdWord, Count:=NoWord2 + 1
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Color = RGB(0, 60, 179)
Loop
' Searching the remaning (till the end of document)
PlayTheSound "W23 - Target Designated.wav"
ErrorReport:
End Sub
The problem is every single special character or number is recognized as a separate word. This means if, for example, I tell it to mark ahead every 50 words, sometimes I'll get a section with 41, sometimes 37, sometimes 46, and so on.
Is there a way to specify that if encounter such and such word, add 1 to the word count ("NoWord" and "NoWord2") and keep going?
EDIT: for those who are curious, this macro is to help me mark my translation quota each day. Say I plan to do 2,000 words a day, I would input "2000" into the text box (the text box will ask me twice about the number of words because sometimes my schedule force me to alternate my quota, such as 1,500 and 2,000 words each day, alternately), and every 2,000 words, there will be a part with blue letters, telling me once I've done translating up to that point, I can stop for the day.