Results 1 to 6 of 6

Thread: Paste selection from excel to word in specific paragraph

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Nov 2016
    Posts
    2
    Location

    Paste selection from excel to word in specific paragraph

    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
    Last edited by Aussiebear; 01-04-2025 at 12:18 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •