PDA

View Full Version : VBA in word?



pominoz
09-03-2012, 10:47 PM
Hi there,

I have never used VBA in a word document before and would like to do a number of things.

Firstly I would like to search through a document and if I find the term ABN, or A.B.N. then I would like to insert our ABN number after the last character (adding a space first)

Is this possible?

Thanks in advance
:dunno

gmaxey
09-04-2012, 03:08 AM
Yes.

Sub ScratchMacro()
'A quick macro scratch pad created by Greg Maxey
Dim oRng As Word.Range
Dim arrStr() As String
Dim i As Long
arrStr = Split("ABN|A.B.N.", "|")
For i = 0 To UBound(arrStr)
Set oRng = ActiveDocument.Content
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = arrStr(i)
.Replacement.Text = "^& your number"
.MatchCase = True
.Execute Replace:=wdReplaceAll
End With
Next i
End Sub