Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to loop MSWORD macro until end of document?

Status
Not open for further replies.

Chavito1983

Technical User
Aug 12, 2008
10
NL
Hi all,

Sorry for the wrong post. This should be the right place then.

Who can help me find a way to loop something until the end of a Word document? I just can't get it to stop.

Primarily, I am trying to loop (or better, alternate) two macros from the insertion point until the end of the document. If possible and easy to do, I would like to also have the option to select some text and run the macros on the selected text instead of the remainder of the document.

The following works. The problem is that there is no way of telling how many times the macros are going to run before the end, so counters are not an option. Each macro grabs a portion of text based on its contents and processes it. The insertion point then moves past the processed section.

Code:
Sub GetFuzzies()

Do
Application.Run MacroName:="macro1"
Application.Run MacroName:="macro2"
Loop

End Sub

Thanks a lot for any help!

Chavo
 
Hi Guys,


First I would like to apologize for not replying earlier. I have been out of town this week.

I see that MakeItSo knows about translation tools. I have to work with Logoport on a regular basis. The problem however is that I don't always have access to an internet connection. On most projects, I'm the only one who works with it, and there is no terminology attached, so the advantage of sharing your translation with others while working is lost.

What I wanted this macro to do was gather as much 100% and fuzzy matches in the translation document, so I can still profit from especially the fuzzies when translating off-line. I then use Trados for further translation. Asking the project engineer for an export of the TM every time I get a job would be too much to ask.

I will try to implement all of your suggestions this weekend and write a decent macro.

Chavo

 
Chavo: I got a simple solution to your problem:
I actually do know this tool you mentioned as well as its... ummm... drawbacks!
(I had the joy of being in the support team for a while...)

There is a very simple way of solving this issue:
a) make a backup copy of your current work status.
b) use the LP function "convert tagging to external", this will give you an document with Trados tagging.
c) make a copy of that doc version and clean it into an empty Trados TM

Voilà, now you have a TRados-tagged file to work with as well as all previous translations of that document in your TM.

Life can be simple.
;-)

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Oh, P.S:

When you are back online, you can of course use the re-conversion function of LP "convert external to LP" to get a functional LP document again.

Before working with LP again, make a copy of your latest doc version and clean it into your LP working memory to have all your latest translations in the TM.
:)

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Ah, me dummy! What a difference a weekend makes...
Of course you want to prefill a TM with the fuzzies still missing in the document; not just profit from what you have translated, but from ALL that is in the LP TM.

I'm afraid, that will be a no go. In order to do so, you would need either

a) In-depth information of LP macros including info on parametres passed or

b) a documentation of the LP client DLL API calls.

I really doubt you will get either of these. And to be honest: if I were support, I would not give them to you either.
Don't get me wrong, but: It would be somewhat daft to lay open the bowels of a worldwide used corporate tool to a translator.
Not only are you not a fixed employee, you are also neither an engineer nor a developer. Not even every engineer has access to this info, and it is good thus, because you would directly access the central server!

I'm afraid, you will not get beyond a crutch solution. Sorry.

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Hi MakeItSo,

What I have assembled so far is indeed a crutch solution, but it does its job for my purpose, without in depth knowledge of the LP bowels. It now gathers all fuzzy segments with their respective source segments from the TM, so I don't have to be afraid of adding a fuzzy segment by accident. I run the macro on a copy of my translation file and add the result to my TM in Trados.

The only problem is that it takes quite a while to run because, as always, LP is quite slow.

Code:
Sub GatherProjectTM()
Dim myString As String
'Check to see if there is something to work with to the right of the insertion point
Selection.MoveEnd Unit:=wdCharacter, Count:=3
'Loop until it runs out of segments
Do Until Selection.Characters.Count < 3
'Run LP Get-macro
    Application.Run Macroname:="Logoport.Logoport1.lpc_open_next"
'Go to the paragraph that contains the matched source segment from the TM
    Selection.Move Unit:=wdParagraph, Count:=-4
'Select the matched source segment
    Selection.MoveEnd Unit:=wdParagraph, Count:=1
'Shrink to leave paragraph mark out
    Selection.MoveEnd Unit:=wdWord, Count:=-1
'Set string to selection
    myString = Selection.Text
'Check to see if there is a match at all
    If myString = "No match" Then
'If not, then delete the segment
    Application.Run Macroname:="Logoport.Logoport1.lpc_close_delete"
'Else, replace original source, with matched source from TM
    Else
    Selection.Move Unit:=wdParagraph, Count:=2
    Selection.MoveEnd Unit:=wdParagraph, Count:=1
    Selection.MoveEnd Unit:=wdWord, Count:=-1
    Selection.Delete
    Selection.InsertAfter (myString)
'Close segment without storing to the TM
    Application.Run Macroname:="Logoport.Logoport1.lpc_close_no_store"
    End If
'Prepare for segment check
    Selection.MoveEnd Unit:=wdCharacter, Count:=3
Loop
End Sub

I extend the selection by 3 characters because at the file end, the LP macro leaves the segment marker closing bracket and the paragraph character to the right of the insertion point. If it is possible to extend by three characters, it is not at the end of the document.

As you can see, the purpose has evolved along with the macro. I know there should be an easier way to work through a selection or the entire document, and it would be nice to have a way to break the loop midway. As you understand, it's an experiment in progress that I work on in my spare time.

Chavo



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top