General XMetaL Discussion
XMetaL Community Forum › General XMetaL Discussion › how do i iterate a document
-
nileshp March 19, 2014 at 4:42 pm
how do i iterate a document
March 19, 2014 at 4:42 pmParticipants 0Replies 1Last Activity 8 years, 10 months agoI'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:
Selection.Find.Execute(“SWNameLong”);
if (rng.CanPaste(swnameshort, false)) {
rng.PasteString(swnameshort);
}
else {
ActiveDocument.Host.Alert(“Cannot replace this instance with a conref.”);
}
}Can someone please help me complete this?
Derek Read March 20, 2014 at 1:36 am
Reply to: how do i iterate a document
March 20, 2014 at 1:36 amPlease 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”);
}[/code]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.
-
AuthorPosts
- You must be logged in to reply to this topic.