Sub CopyFilterResult()
' This loop repeats for generate multiple word documents by ID
' in the range
Dim objWordApp As Word.Application
Dim objWord As Word.Document
Dim i As Long
On Error GoTo errHandle
Set objWordApp = New Word.Application
Set objWord = objWordApp.Documents.Add
objWord.Application.Visible = True
Sheets("Sheet4").Select
Cells.Select
Selection.Clear
Sheets("Target").Select
Range("A2").Select
Selection.Clear
With Worksheets("id")
lastcell = Range("A" & Cells.Rows.Count).End(xlUp).Row
For i = 0 To lastcell
.Range("A1").Offset(1, 0).Copy Sheets("Target").Range("A2")
Next i
End With
Worksheets("Sheet1").Range("A1").CurrentRegion.AdvancedFilter _
Action:=xlFilterCopy, CriteriaRange:=Worksheets("Target").Range("A1:A2").SpecialCells(xlCellTypeVisible), _
CopyToRange:=Worksheets("Sheet4").Range("A1"), Unique:=True
With Worksheets("Sheet4")
Set rngCopy = .Range("A1:D" & .Range("A" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeVisible)
End With
With objWord.Application
.Selection.Style = .ActiveDocument.Styles("Normal")
.Selection.TypeParagraph
rngCopy.Copy
.Selection.PasteExcelTable False, False, False
End With
objWord.SaveAs
FPath = "desktop"
FName = Worksheets("Sheet4").Range("A2").Value
ActiveDocument.SaveAs Filename:=FPath & "\" & FName, _
FileFormat:=wdFormatDocument
objWord.Close
objWordApp.Quit
errExit:
Set objSel = Nothing
Set objWord = Nothing
Set objWordApp = Nothing
Exit Sub
errHandle:
MsgBox Err.Description
Resume errExit
End Sub
_______________________________________________________
Here is my code
dont know whether what loop i can use, in order to generate two word document at the same time.Thanks for your reply!!!