Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
What is this?Syndicate this content

Text replacement in Text Frames

This source code snippet requires TX Text Control ActiveX
Author:TX Text Control Support Department
Language:Visual Basic
Version:1.0
Released:August 19, 2005
Last modified:January 11, 2008
Requirements:TX Text Control ActiveX with Visual Basic
Download code:tx_sample_frame_replace.zip Download [3.96 KB, ZIP]
Click to enlarge

One of the main advantages of text frames is the ability to handle each one of them separately. Therefore, it is possible to search for a string in a specific text frame only.

To search for all instances of a string in the main text and all inserted text frames, you just have to loop through all text frames. The following code snippet illustates how to loop through all text frames, using the ObjectNext method:

  1. Do
  2. tfID = tx.ObjectNext(i, &H20)
  3.  
  4. If tfID = 0 Then
  5. Exit Do
  6. Else
  7. tx.TextFrameSelect (tfID)
  8. count = count + findReplaceText(text, replaceWith)
  9. tx.TextFrameSelect -1
  10. End If
  11.  
  12. i = i + 1
  13. Loop

The findReplaceNext function simply uses the Find method to replace all instances of the string in the document. In the sample, our function additionally returns the number of replaced instances.

At least a trial version of TX Text Control ActiveX 12.0 and Visual Basic 6.0 is required to start the sample application.

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place