code:

Can't Copy and Paste this?

Click here for a copy-and-paste friendly version of this code!

 

Terms of Agreement:   

By using this code, you agree to the following terms...   

1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.   

2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   

3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 

4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.  

//     

'------------------------------------------------------------------------------

'FILE DESCRIPTION: Columna search-and-replace

'------------------------------------------------------------------------------

Sub ColReplace ()

'If no text selected, exit

if ActiveDocument.Selection = "" Then Exit Sub

strTitle = "Columna Search-and-Replace"

y2 = ActiveDocument.Selection.CurrentLin

x2 = ActiveDocument.Selection.CurrentColumn

y1 = ActiveDocument.Selection.TopLine

x1 = Int( x2 - Instrb(ActiveDocument.Selection, vbCR)/2 + .5)

strFind = Input( "Enter word to search for", strTitle )

if strFind = "" Then Exit Sub

strReplace = InputBox("Replace with what word?", strTitle )

ActiveDocument.Selection.EndOfLin

ActiveDocument.Selection = ActiveDocument.Selection + stfFind

do while y1 <= y2

ActiveDocument.Selection.GoToLine y1

ActiveDocument.Selection.StartOfLine

do while ActiveDocument.Selection.CurrentColumn < x1

ActiveDocument.Selection.CharRight dfMove, 1

Loop

do while ActiveDocument.Selection.CurrentColumn < x2

ActiveDocument.Selection.CharRight dsExtend, 1

Loop

ActiveDocument.Selection.ReplaceText strFind, strReplace

y1 = y1 + 1

Loop

ActiveDocument.Selection.EndOfLine

for i = 1 To Len( strFind )

ActiveDocument.Selection.BackSpace

Next

End Sub