Hello Jimbo42,
I have added the macro below to the "Print to Word" button in the attached workbook.
' Thread: http://www.excelforum.com/excel-programming/801746-add-text-to-string-output-to-wordpad-word.html
' Poster: Jimbo42
' Written: November 16, 2011
' Author: Leith Ross
Sub CopyToWordFile()
Dim Cell As Range
Dim Rng As Range
Dim RngEnd As Range
Dim Text As String
Dim wdApp As Object
Dim wdDoc As Object
Dim wdRng As Object
Dim Wks As Worksheet
Set Wks = ActiveSheet
Set Rng = Wks.Range("A2")
Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = Wks.Range(Rng, RngEnd)
For Each Cell In Rng
If VBA.StrComp(Cell, "NR", vbTextCompare) = 0 Then
Text = Text & Cell.Offset(0, 1) & ", "
End If
Next Cell
If Text <> "" Then
Text = "The following branches have recovered: " & Left(Text, Len(Text) - 2)
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Add
Set wdRng = wdDoc.Content
wdApp.Visible = True
wdRng.InsertAfter Text
On Error Resume Next
wdDoc.Close -2
End If
End Sub
Bookmarks