Advertisement
Guest User

Untitled

a guest
Oct 6th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub TextReplace()
  2. Dim wdDoc As Object
  3. Dim oRng As Object
  4. Dim placeholderNames(0) As String
  5. Dim placeholderValues(0) As String
  6. Dim name As String
  7. Dim value As String
  8. Dim index As Integer
  9. Dim i As Integer
  10.     On Error GoTo ErrHandler
  11.     placeholderNames(0) = "[[ИНН]]"
  12.     placeholderValues(0) = "1234567890"
  13.     If TypeName(ActiveWindow) = "Inspector" Then
  14.         If ActiveInspector.IsWordMail And ActiveInspector.EditorType = olEditorWord Then
  15.             Set wdDoc = ActiveInspector.WordEditor
  16.             Set oRng = wdDoc.Range
  17.             With oRng.Find
  18.                 For i = LBound(placeholderNames) To UBound(placeholderNames)
  19.                     name = placeholderNames(i)
  20.                     value = placeholderValues(i)
  21.                     Do While .Execute(findText:=name)
  22.                         oRng.Text = value
  23.                         oRng.collapse 0
  24.  
  25.                     Loop
  26.                 Next i
  27.             End With
  28.         End If
  29.     End If
  30. lbl_Exit:
  31.     Exit Sub
  32. ErrHandler:
  33.     Beep
  34.     Resume lbl_Exit
  35. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement