atw: Insert wrapper text VBA for Geoffrey

  • From: Steve Hudson <sh1448291904@xxxxxxxxx>
  • To: austechwriter@xxxxxxxxxxxxx
  • Date: Thu, 4 Dec 2014 20:24:50 +1100

The problem with the suggested solution is there is no .text in Geoffrey's
fields - they are graphics. So, we have to work with the range object as
shown below.

Remember, the Range object is king for working in the document. Avoid using
Selection in VBA as when it changes it triggers all sorts of funky
background processing as if we were truly typing.


Sub BraKet()
   InsertWrapper Selection.Range, "(", ")"
End Sub


Sub InsertWrapper(R As Range, Prefix As String, Suffix As String)
Dim Worker As Range


'lets insert the suffix first
Set Worker = R.Duplicate 'so we dont interfere with the selected range
Worker.Collapse wdCollapseEnd
Worker.InsertAfter Suffix

'now the prefix
Set Worker = R.Duplicate 'no interfere
Worker.Collapse wdCollapseStart
Worker.InsertAfter Prefix

'cleanup
Set Worker = Nothing

End Sub

Other related posts:

  • » atw: Insert wrapper text VBA for Geoffrey - Steve Hudson