title: Dynamically select last row of a worksheet and enter selected data into an existing table in a word doc
body: <p>Hi I’m a nube to excel VBA and would appreciate it greatly if someone could assist me in this issue.
  I’ve spent over 5 days researching and reading, trying to solve this issue and can’t get the required result can anyone please help.
  I’m using a userform to submit data to a worksheet then the above vba to open a word template, dynamically select the last line of the worksheet and enter selected cell data into a pre-existing table at various placeholder bookmarks within a word template.
  The code always pastes the data above the table and not in it.
  Here's the code i'm using</p>
  
  <pre><code>Sub testdata()
  'declare variables
      Dim wdDoc As Word.Document
      Dim wdApp As Word.Application
  'declare variable for save  format
      Dim savename As String
  'declare fileext type for differnt versions of word
      Dim fileext As String
      'start word
      Set wdApp = New Word.Application
  'make it visible and activate it
      With wdApp
  'uncomment 2 lines below to see word on screen
          .Visible = True
          .Activate
  'opens a word doc
          .Documents.Add "C:\xxx\xxx\excel_project\test.docx"
   'collect data range ref number
           Range("A1").End(xlDown).Copy
  'selects  the item bookmark in word template
           .Selection.GoTo What:=-1, Name:="Item"
  'paste into word doc
          .Selection.Paste
   'test version type of word
          If .Version &lt;= 11 Then
              fileext = ".doc"
          Else
              fileext = ".docx"
          End If
  'saves doc with specific timedate name
          savename = "C:\xxx\xxx\excel_project\test" &amp; _
          Format(Now, "dd-mm-yyyy hh-mm-ss") &amp; fileext
  'changes save as method depended on word version
          If .Version &lt;= 12 Then
              .ActiveDocument.SaveAs savename
          Else
              .ActiveDocument.SaveAs2 savename
          End If
  'closes the doc
          .ActiveDocument.Close
  'closes word
          .Quit
       End With
  End Sub
  </code></pre>
  
  <p>One source of help suggested using
  `</p>
  
  <pre><code>Sub FnBookMarkInsertAfter()
     Dim objWord
     Dim objDoc
     Dim objRange
     Set objWord = CreateObject("Word.Application")
     Set objDoc = objWord.Documents.Open("C:\xxx\xxx\excel_project\test.docx")
     objWord.Visible = True
      Set objRange = objDoc.Bookmarks("item").Range
      objRange.InsertAfter ("..........I will be added AFTER bookmark")
  End Sub
  </code></pre>
  
  <p>`
  This places the string of text into the table and I can’t find a way to make it dynamically select the last row and hence the required data.</p>
  
  <p>Any help would be greatly appreciated</p>