General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion how do i iterate a document

  • nileshp

    how do i iterate a document

    Participants 0
    Replies 1
    Last Activity 8 years, 10 months ago

    I'm writing a macro to find a string and replace it with a conref. I am using the Find function. However, I'm not able to find a way to detect that the control has reached the end of the document to end the operation.

    For example, I want to display a message indicating that the Find has reached the end of the document.

    Here is my code snippet:
    if (rng.CanPaste(swnameshort, false)) {
    else {
    ActiveDocument.Host.Alert(“Cannot replace this instance with a conref.”);

    Can someone please help me complete this?


    Derek Read

    Reply to: how do i iterate a document

    Please have a look at the XMetaL Developer Programmers Guide documentation for this API as it contains some useful information that will help here.

    Essentially this API returns a boolean value set to true/false when it finds/does not find what you are asking it to locate. So, your script logic can include something similar to the following:

    [code]//XMetaL Script Language JScript:
    if(Selection.Find.Execute(“SWNameLong”)) {
      Application.Alert(“found it”);
    else {
      Application.Alert(“unable to find it”);

    Hopefully you can integrate that type of logic into your script.

    Aside: I'm not sure why your script uses both Selection and Range objects, but it is a script snippet after all and you don't show how you are setting up the Range or subsequent usage of it. Maybe there is a good reason for that.


  • You must be logged in to reply to this topic.

Lost Your Password?