Option
Explicit
Sub
WordDemo()
Dim
c
As
Range, rngTo
As
Range
Dim
strText
As
String
strText = Chr(WorksheetFunction.RandBetween(65, 90))
ThisWorkbook.Sheets.Add
For
Each
c
In
Range(
"A2:A4"
)
c.Value = strText & Format(c.Row,
"000"
)
Next
c
ActiveSheet.UsedRange.Copy Destination:=Range(
"A6"
)
ActiveSheet.UsedRange.Copy Destination:=Range(
"A11"
)
Set
rngTo = Range(
"A:A"
).ColumnDifferences(Comparison:=Range(
"A65536"
))
strText =
""
For
Each
c
In
rngTo
strText = strText & c.Value & Chr(10)
Next
c
Dim
oWordApp
As
Word.Application
Dim
oWordDoc
As
Word.Document
Dim
wdr
As
Word.Range
Set
oWordApp = CreateObject(
"Word.Application"
)
Set
oWordDoc = oWordApp.Documents.Open(
"C:\Temp\Matchcodes.docx"
)
Set
wdr = oWordDoc.Content
wdr.InsertAfter strText
oWordDoc.Close
oWordApp.Quit
End
Sub