Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Chavito1983 (TechnicalUser) (OP)
12 Aug 08 12:40
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  
SkipVought (Programmer)
12 Aug 08 13:02



Do you think that it might be a good idea to post your macro code?

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

TonyJollans (Programmer)
12 Aug 08 13:48
You need to know where you are in the document in order to be able to tell when  you are at the end. Nothing in the little bit of code has that information - how do macro1 and macro2 know where they are? As Skip says, for anybody to help you have to give a little bit more detail.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website

fumei (TechnicalUser)
12 Aug 08 14:10
"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."

Use:  Selection.Text

Other than that, Skip and Tony are right, we need much more information than you are giving.

FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?

Gerry
My paintings and sculpture
 

Chavito1983 (TechnicalUser) (OP)
12 Aug 08 14:30
Hi guys,

Thanks for the input. The problem is that I can't send you the macros' code. They are in a locked project by another engineer. I only know I can access them in this way.

So, there isn't much other info I can give you.

@Fumei: I did find the Selection.Text option, but I do not know how to apply the macros to the selection.

Chavo
Chavito1983 (TechnicalUser) (OP)
12 Aug 08 14:41
Before turning to this site, I have been looking at three options, none of which I have been able to get working:

- Finding a coded method of recognizing the end of the document
- Checking whether there is text to the right of the insertion point before calling the first macro
- Adding a final marker at the end of the document and checking whether it still is in the remainder before calling the first macro

Any of these options are fine, but the first two would be best because they don't modify the original document.

Chavo
SkipVought (Programmer)
12 Aug 08 14:45






"So, there isn't much other info I can give you."

So there isn't much other help I can offer you.

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

Chavito1983 (TechnicalUser) (OP)
12 Aug 08 15:19
Hi Skip,

I do appreciate your effort to help me. Is there any other information that I might be able to give to get started?

The best working option I got until now was this:

CODE

Sub GetFuzzies()
Dim i As Long
i = 1

Do Until i > ActiveDocument.Sentences.Count
    Application.Run MacroName:="macro1"
    Application.Run MacroName:="macro2"
    i = i + 1
Loop
End Sub

Although the amount of sentences is not equal to the amount of loops required, the difference is small enough for short documents. However, in 80 page documents, the discrepancy increases to such an extent that it is no longer a workable option.

Chavo
 
TonyJollans (Programmer)
12 Aug 08 15:55
This is crazy - tell your boss it's crazy. You have to know something about the macros.

What do the macros do? How do they know when they've got to the end of the document? What do they do when they've got to the end of the document?

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website

Chavito1983 (TechnicalUser) (OP)
12 Aug 08 16:26
Haha.. I could tell my boss it's crazy: in a mirror. I am my own boss and use a commercially available tool for translating. The tool has a Word template that interacts with my translation software.

The first macro selects a chunk of text to be translated, starting at the insertion point and ending at a specific point, based on several rules (more or less a sentence), and then goes on to the translation software to check if there is a similar or identical sentence with its translation available. If so, it is copied into the document.

The second macro confirms the translation without storing it back to the translation software.

As I use various tools, I want to be able to process an entire document with a single command before changing to a different tool. This option is not provided with the commercial software, so I am trying to get it to work myself.

I'm checking out now as it's 10:30 PM in CET.

Regards,

Chavo
macropod (TechnicalUser)
12 Aug 08 18:10
Hi Chavo,

Quote:

The first macro selects a chunk of text to be translated, starting at the insertion point and ending at a specific point, based on several rules (more or less a sentence
How does the first macro 'select' its chunk of text? Do you make the selection, or is the selection process automated in some way? What are these 'several rules' you mention?
Allowing for the possibility that your macros change the sentence count (and in the absence of anything more useful to work with), perhaps you could use something like:

CODE

Sub GetFuzzies()
Dim i As Long
For i = ActiveDocument.Sentences.Count to 1 Step -1
    Application.Run MacroName:="macro1"
    Application.Run MacroName:="macro2"
Next
End Sub
Cheers

[MS MVP - Word]

Chavito1983 (TechnicalUser) (OP)
13 Aug 08 3:17
Hi Macropod,

After a good night sleep and a new golden idea I finally got it to work, at least, in a basic way.

The following code extends the selection to see if it's possible. If it can be extended by 3 characters, the Loop knows it's not at the end of the file. If not, the file end has been reached and the loop exits. This doesn't allow for selecting a chunk of text before running, but it will do for now.

CODE

Sub GetFuzzies()

Selection.MoveEnd Unit:=wdCharacter, Count:=3

Do Until Selection.Characters.Count < 3
    Application.Run MacroName:="macro1"
    Application.Run MacroName:="macr02"
    Selection.MoveEnd Unit:=wdCharacter, Count:=3
Loop
End Sub

As for your question, the first macro makes its own selection. I just put te insertion point anywhere in the file and it will proceed from there. It has a mechanism (unknown to me) to determine whether there is anything to the right of the insertion point. If there is, it runs. If not, it doesn't. The rules are based on the encountered characters. The selection is extended to (more or less) the first [^t^p:.?!] to the right of the insertion point.

Hopefully this makes it all a bit clearer. I find it hard to explain what happens because I see it happening 100s of times each day. The macros do indeed increase the sentence count: the source chunk is hidden and the target chunk is pasted into the file, both surrounded with markers to identify them.

Chavo
TonyJollans (Programmer)
13 Aug 08 4:52
If your macros work with the insertion point and you don't change that as you're progressing, it follows that they change it. Assuming all the work happens in the same window, you can check the insertion point (Selection.End).

The implication of you not knowing is that the macros don't pass any indication of success or failure so, how you will know when you've reached the end is for you to experiment a little. Perhaps the insertion point is left unchanged - in which case Selection.End before the call and after the call wil be the same. Or perhaps it leaves it at - or near - the end of the document: ActiveDocument.Range.End - perhaps ActiveDocument.Range.End-1 - as I said, it's going to need some trial and error.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website

fumei (TechnicalUser)
13 Aug 08 20:08
"As for your question, the first macro makes its own selection."

This is impossible.  Literally.  Macros do not make their "own" selection. Macros do, and ONLY do, what they are told to do...by a programmer.

There [/b]must[/b] be rules of logic in there.  If you do not know what they are - and apparently you do not - then it is difficult to help.

The original question was regarding continuing until the end of the document.  This is a normal and very common requirement.  I do it all the time.  The procedure is fairly easy to accomplish....and if we had an idea of what is trying to be accomplished, it would be easy to say so.  You state:

"The following code extends the selection to see if it's possible. If it can be extended by 3 characters, "

with no explanation whatsoever.  WHY 3 characters?????  Why not, 6???  Or 7?  Or 2?  Or 1?  No explanatuon of the logic.

You have these three "requirements":

- Finding a coded method of recognizing the end of the document
- Checking whether there is text to the right of the insertion point before calling the first macro
- Adding a final marker at the end of the document and checking whether it still is in the remainder before calling the first macro

The end of the document...is the end of the document.  One "coded" infoirmation is ActiveDocument.Range.End.  This is simply a number.  The end of the document.  However, with good coding, this is rarely needed.  You use a Do While statement actioning on the Range of the document.  It will processing until the end, and stop.

As for checking if there is text to the right of the insertion, that is simple.  Check the insertion (Selection) .End number, and if it is less than the document Range.End...yes, there is text to the right.

Ihave to say that using Selection (the insertion point) is NOT a good way to process documents.  Range is far better.

FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?

Gerry
My paintings and sculpture
 

shinbi (MIS)
14 Aug 08 19:16
Hi Chavo,
I was looking for similar process of running macro to the end of document and I combined yours with some other property.  This worked out for me.  

CODE

Dim i As Long
i = 1
Do Until i > ActiveDocument.BuiltInDocumentProperties("Number of Pages")

`Your Stuff

    i = i + 1
Loop
TonyJollans (Programmer)
14 Aug 08 19:30
shinbi,

That is as arbitrary as Chavo's check on sentences. It may or may not work depending on the relationship between the process and a page of the document.

Chavo,

Do your macros change the text at the insertion point, or just at some point forward from it? Or do they leave the insertion point just after some identifiable text. I'm wondering if you can check for the markers you say are added to tell whether or not they have run, assuming that  having run means, effectively, not finished yet.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website

MakeItSo (Programmer)
15 Aug 08 9:41
Hi Chavo,

there are two possiblities I can see so far.

1) If you are working with selection, you could make use of the "Range":

CODE

Do
...
Loop until Selection.Range.End=ActiveDocument.Range.End

2) I know quite a few CAT tools and usually they all have a "pretranslate" option which seems to be what you are trying to re-program. Can't you just make use of the built-in functions of that CAT tool?

Cheers,
MakeItSo

"We had to turn off that service to comply with the CDA Bill."
- The Bastard Operator From Hell

MakeItSo (Programmer)
15 Aug 08 9:54
P.S: I am a localisation engineer. If you told me what exactly you are trying to perform and with which CAT tool I might be able to provide more detailed help.
winky smile

"We had to turn off that service to comply with the CDA Bill."
- The Bastard Operator From Hell

TonyJollans (Programmer)
15 Aug 08 11:14
Hi MakeItSo,

The trouble with checking selection against end of document is it assumes that the invoked macros put the selection there when they have finished, and nothing Chavo has said so far suggests tha that is the case.

I do agree it could help to know what the package is - quite often they have trial downloads.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website

MakeItSo (Programmer)
15 Aug 08 11:30
hi Tony,

Chavo said, it's a translation tool. These tools usually work with the clipboard, i.e. the copy the currently selected segment to the clipboard, query the clipboard contents against the translation memory (database) and the paste the translated contents back from the TM if a translation was found.
The reason for this seemingly unnnecessarily longwinded procedure is simple: they don't want to lose formatting information, as this is also stored in the translation database.

Hence the selection **should** be were the current cursor position/selection is, only extended until the next end-of-segment marker, which is e.g. "." ";" ":" or end of paragraph.

Now that I talk of it, this might be closer to a functioning check in this case:

CODE

Loop Until Selection.Range.Sentences(1).End+1=ActiveDocument.Range.End
'extend by trailing paragrpah mark which is a sentence of its own

Still not all too reliable for my taste. Need more info on what Chavo actually wants to achieve.

"We had to turn off that service to comply with the CDA Bill."
- The Bastard Operator From Hell

fumei (TechnicalUser)
15 Aug 08 20:17
"Need more info on what Chavo actually wants to achieve. "

Indeed.

FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?

Gerry
My paintings and sculpture
 

Chavito1983 (TechnicalUser) (OP)
22 Aug 08 12:06
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

 
MakeItSo (Programmer)
23 Aug 08 10:53
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.
winky smile

"We had to turn off that service to comply with the CDA Bill."
- The Bastard Operator From Hell

MakeItSo (Programmer)
23 Aug 08 10:56
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.
smile

"We had to turn off that service to comply with the CDA Bill."
- The Bastard Operator From Hell

MakeItSo (Programmer)
25 Aug 08 6:46
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.

"We had to turn off that service to comply with the CDA Bill."
- The Bastard Operator From Hell

Chavito1983 (TechnicalUser) (OP)
25 Aug 08 9:21
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



 

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close