Hi, anyone please help me solve this, the code below is selecting the fields to be pasted in word, but its creating a new word file and pasting the selection.
I need anyone to help me quickly with pasting the selection in the word file i choose and in paragraph 5. the word file already has content, this code is just to fit the table from excel to word. please help
Sub Test() Dim tbl As Excel.Range Dim WordApp As Word.Application Dim myDoc As Word.Document Dim WordTable As Word.Table Sheets("Sheet1").Select With ActiveSheet .AutoFilterMode = False .Range("A1:I1").AutoFilter .Range("A1:I1").AutoFilter Field:=1, Criteria1:=InputBox("Please provide Country name") End With With ActiveSheet.AutoFilter.Range .Offset(1, 0).Resize(.Rows.Count - 1).Copy End With ' Set tbl = ThisWorkbook.Worksheets(Sheet1.Name).ListObjects("Table1").Range Application.GetOpenFilename ("Word Files (*.doc*), *.doc*") WordApp.Visible = True WordApp.Activate ' tbl.Copy myDoc.Paragraphs(1).Range.PasteExcelTable _ LinkedToExcel:=False, _ WordFormatting:=False, _ RTF:=False Set WordTable = myDoc.Tables(1) WordTable.AutoFitBehavior (wdAutoFitWindow) EndRoutine: ' Optimize Code Application.ScreenUpdating = True Application.EnableEvents = True ' Clear The Clipboard Application.CutCopyMode = False ' Opening the word document ' Set wordapp = CreateObject("word.Application") ' wordapp.documents.Open ' wordapp.Visible = True![]()


Reply With Quote

