0

I am trying to write a macro that inserts "!!!" at the beginning of a textbox if there is a "XX" located in any part of that text box. Ideally the macro will run this procedure for every textbox in the presentation, but I can figure out how to loop it through if someone can help me with the basic procedure.

For example, a text box with the following text:

  • I ate XX hamburgers on XX/XX/20XX

would become

  • !!!I ate XX hamburgers on XX/XX/20XX
Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
dsal1951
  • 1,630
  • 1
  • 16
  • 20

2 Answers2

0

I hope this can help.

Sub test()
Dim TestString As String

TestString = "I ate XX hamburgers on XX/XX/20XX"

Variable = InStr(1, TestString, "X")

If Variable > 0 Then
    output = "!! " & TestString
End If

Debug.Print output

End Sub

Here TestString = your input string

The InStr function tests if "X" is present in the string, if it is then "!!" is joined to the variable "Output"

This should be quite easy to adapt?

Kazimierz Jawor
  • 18,861
  • 7
  • 35
  • 55
Jiminy Cricket
  • 1,377
  • 2
  • 15
  • 24
0

i hope this will help you.

Sub test()

Dim s As String
s = "Test XX"

If InStr(1, s, XX, vbTextCompare) Then
s = "!!!" + s
End If

MsgBox s

End Sub
ruedi
  • 5,365
  • 15
  • 52
  • 88