title: VBA Paste each string of a range of cells from an excel file to a word labels template
body: <p>to do that i started with the microsoft word 16.0 object library.
  I need to take the value of the E10 cell (number). Who said how many lines i will have in my hostname's column.</p>
  <p>to just copy that range of cells and export each one of those strings in a label formated word.
  At the time this code insert all the value just in the first label with &lt;&gt; and not each strings to each label...</p>
  <p>Thanks you.</p>
  <p><a href="https://i.stack.imgur.com/g27UM.png" rel="nofollow noreferrer">Excel</a>
  <a href="https://i.stack.imgur.com/vs4Wl.png" rel="nofollow noreferrer">Word labels template</a></p>
  <pre><code>Sub LabelMerge()
  Dim oWord As Word.Application, oDoc As Word.Document
  Dim strFile As String
  Dim sPath As String
  Dim i As Integer
  Dim oHeaders As Range 'tab var data
  
  Set oHeaders = Range(&quot;D48&quot;).CurrentRegion.Rows(1) 'select data from excel
  sPath = ThisWorkbook.FullName 'path acces
   
  Set oWord = CreateObject(&quot;Word.Application&quot;) 'create object word
  'Set oDoc = oWord.Documents.add
  Set oDoc = oWord.Documents.Open(&quot;file.docx&quot;)
  oWord.Visible = True
  
  oDoc.MailMerge.MainDocumentType = wdMailingLabels 'publipostage
  'oWord. Dialogs (wdDialogLabeloptions) .Show
  'oDoc.Activate
  
  Dim x As Integer
  x = 48 + Range(&quot;E10&quot;).Value
  
  With oDoc.MailMerge.Fields
          For i = 48 To x 'while i &lt; lenght data
          .Add oWord.Selection.Range, Cells(i, 4).Value
      'oWord.Selection.TypeParagraph ‘OR: TypeText &quot; &quot;
      Next i
  End With
  
  oDoc.MailMerge.OpenDataSource sPath
  oWord.WordBasic.mailmergepropagatelabel
  oDoc.MailMerge.ViewMailMergeFieldCodes = False
  oDoc.ActiveWindow.View.ShowFieldCodes = False
  
  'oDoc.MailMerge.Destination = wdSendToNewDocument 'add to doc
  'oDoc.MailMerge.Execute
  
  Set oDoc = Nothing
  Set oWord = Nothing
  
  End Sub
  </code></pre>