hi all, I have the following code which isnt working because the “piece” range in the collection fails on the Piece.copy method. I cant think of what I am doing wrong. Help appreciated!!
cheers,
Dom
Public Sub GenerateDocument(Tag As String) Dim createdDocument As Document Dim outputContent As New Collection Dim i As Integer Dim piece As Range ‘Select the document ActiveDocument.Range(Start:=0, End:=ActiveDocument.Content.End).Select On Error GoTo err: ‘find all the matching bits With Selection.Find .ClearFormatting .Text = “[” + Tag + “]*[/” .Replacement.Text = “” .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True While .Execute outputContent.Add (Selection.Range) Wend End With ‘ create a new document Set createdDocument = Application.Documents.Add ‘put the content in it For Each piece In outputContent piece.Copy createdDocument.Range.Paste Next piece Exit Sub err: MsgBox “GenerateDoc: ” & err.Desciption End Sub