Option Explicit Sub Main ' Find a block of text in syntax window and replace it by another block. ' Requirements: ' Enter the target lines (those to be replaced) at the beginning of the designated window. ' Enter 2 \\'s at the beginning of the following line ' Enter the replacement lines starting immediately after the above mentionned \\\\ ' Enter 2 \\'s at the beginning of the following line ' Do not leave any trailing spaces at the end of your lines of codes ' Caveats: ' The script replaces consecutive lines which are *identical* to the target lines by ' the replacement lines. ' Posted to spss newsgroup by Raynald Levesque on 2003/09/10. Dim objSyntaxDoc As ISpssSyntaxDoc Dim strSynCmd As String Dim intPos As Integer Dim strScript As String Dim strReplace As String Dim strFind As String Set objSyntaxDoc=objSpssApp.GetDesignatedSyntaxDoc Debug.Print objSyntaxDoc.GetDocumentPath 'Save designated syntax window (if there is a problem, use can undo the "find & replace" 'by reloading the file). If objSyntaxDoc.GetDocumentPath <> "" Then objSyntaxDoc.SaveAs (objSyntaxDoc.GetDocumentPath) Else MsgBox ("Save the designated syntax window " & vbCrLf & "then try again.") Exit Sub End If Debug.Clear strSynCmd = objSyntaxDoc.Text Debug.Print strSynCmd strFind = Left(strSynCmd,InStr(strSynCmd,"\\\\") - 1) Debug.Print "strFind=" & vbCrLf & strFind 'Redefine rest of syntax strSynCmd = Mid(strSynCmd,InStr(strSynCmd,"\\\\") + 4) Debug.Print "Rest of syntax " & vbCrLf & strSynCmd strReplace = Left(strSynCmd,InStr(strSynCmd,"\\\\") - 1) Debug.Print "Replace by" & vbCrLf & strReplace 'Redefine rest of syntax strSynCmd = Mid(strSynCmd,InStr(strSynCmd,"\\\\") + 4) Debug.Print "Rest of syntax " & vbCrLf & strSynCmd strSynCmd=Replace(strSynCmd,strFind,strReplace) Debug.Print strSynCmd objSyntaxDoc.Text = strFind & "\\\\" & vbCrLf & strReplace & "\\\\" & vbCrLf & strSynCmd Set objSyntaxDoc=Nothing End Sub