I have been working on a macro that adds data to a page on Word in the form of a Mail Merge label. I found a code online that gets all the data into one page on Word. I was wondering if there is a way that the data from each row in my Excel Spreadsheet could go to different pages in Word? The code is given below.
Sub LabelMerge()
Dim oWord As Word.Application, oDoc As Word.Document
Dim sPath As String, I As Integer, oHeaders As Range
Application.ScreenUpdating = False
Set oHeaders = Range("A1").CurrentRegion.Rows(1)
sPath = ThisWorkbook.FullName
Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Add
oWord.Visible = True
oDoc.MailMerge.MainDocumentType = wdMailingLabels
oWord.Dialogs(wdDialogLabelOptions).Show
oDoc.Activate
With oDoc.MailMerge.Fields
For I = 1 To oHeaders.Columns.Count
.Add oWord.Selection.Range, oHeaders.Cells(1, I)
oWord.Selection.TypeText " "
Next I
End With
oDoc.MailMerge.OpenDataSource sPath
oWord.WordBasic.mailmergepropagatelabel
oDoc.MailMerge.ViewMailMergeFieldCodes = False
oDoc.ActiveWindow.View.ShowFieldCodes = False
Set oDoc = Nothing
Set oWord = Nothing
Application.ScreenUpdating = True
End Sub
This is how the data looks like before and after the code is run from the VBA Editor. I am fairly new to VBA and would appreciate any help!
Sample Data in Excel
Labels on Word