title: Paste table from multiple excel sheets into word file and name word as sheet name VBA
body: <p>I have excel file with many sheets. In each sheet I have 3 tables which I need to paste into a word document. I need to create a word template and name it as sheet and paste 2 tables.</p>
  
  <pre><code>Sub Separate()
  
   'Remember: this code requires a referece to the Word object model
  
   'dimension some local variables
  Dim rng As Range 'our source range
  Dim wdApp As New Word.Application 'a new instance of Word
  Dim wdDoc As Word.Document 'our new Word document
  Dim t As Word.Range 'the new table in Word as a range
  Dim myWordFile As String 'path to Word template
  
  
   'initialize the Word template path
   'here, it's set to be in the same directory as our source workbook
  myWordFile = ThisWorkbook.Path &amp; "\DocWithTableStyle.dot"
  
   'get the range of the contiguous data from Cell A1
  Set rng = Range("A1").CurrentRegion
   'you can do some pre-formatting with the range here
  rng.HorizontalAlignment = xlCenter 'center align the data
  rng.Copy 'copy the range
  
   'open a new word document from the template
  Set wdDoc = wdApp.Documents.Add(myWordFile)
  
  Set t = wdDoc.Content 'set the range in Word
  t.Paste 'paste in the table
  With t 'working with the table range
      .Style = "GreenBar" 'set the style created for the table
       'we can use the range object to do some more formatting
       'here, I'm matching the table with using the Excel range's properties
      .Tables(1).Columns.SetWidth (rng.Width / rng.Columns.Count), wdAdjustSameWidth
  End With
  
   'until now the Word app has been a background process
  wdApp.Visible = True
   'we could use the Word app object to finish off
   'you may also want to things like generate a filename and save the file
  wdApp.Activate
  
  End Sub
  </code></pre>
  
  <p>This is what I was trying but getting error</p>
  
  <blockquote>
  <pre><code>---------------------------
  Microsoft Visual Basic for Applications
  ---------------------------
  Compile error:
  
  User-defined type not defined
  ---------------------------
  OK   Help   
  ---------------------------
  </code></pre>
  </blockquote>
  
  <p>reference to word and excel are selected </p>