I'm writing a macro to simplify the merging of labels from Excel to Word, I've got the code below but I need to adjust the font size, bold or italic some of the merge fields, add some text and would like to have the macro select 30per sheet labels at the start every time and always use as range named aa_Loom_Labels as the data source. I've added notes to the code where I'm trying to achieve the formatting, some assistance would be awesome!
Code:
Sub aaa_Label_Merge()
Dim oWord As Object
Dim oDoc As Object
Dim sPath As String
Dim oTable As Object
Dim oRng As Object
Dim oCell As Object
Dim i As Long
sPath = ThisWorkbook.FullName
Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Add
oWord.Visible = True
oDoc.Activate
oDoc.MailMerge.MainDocumentType = 1
oWord.Dialogs(1367).Show
'Always select 30per sheet labels as the type
Set oTable = oDoc.Tables(1)
Set oRng = oTable.Cell(1, 1).Range
oRng.End = oRng.End - 1
With oDoc.MailMerge.Fields
'this merge field needs to be bold and 18pt font
.Add oRng, "LABEL"
oRng.Start = oTable.Cell(1, 1).Range.End - 1
oRng.InsertParagraph
oRng.Collapse 0
'this merge field needs a text label "LOCATION:" inserted before it
.Add oRng, "LOCATION"
oRng.Start = oTable.Cell(1, 1).Range.End - 1
oRng.InsertParagraph
oRng.Collapse 0
'the remaining merge fields need to be all on the same line and italics
.Add oRng, "TYPE"
oRng.Start = oTable.Cell(1, 1).Range.End - 1
oRng.InsertParagraph
oRng.Collapse 0
.Add oRng, "CABLE"
oRng.Start = oTable.Cell(1, 1).Range.End - 1
oRng.InsertParagraph
oRng.Collapse 0
.Add oRng, "LENGTH"
oRng.Start = oTable.Cell(1, 1).Range.End - 1
oRng.Text = " "
End With
Set oRng = oTable.Cell(1, 1).Range
oRng.End = oRng.End - 1
For i = 2 To oTable.Range.Cells.Count
If oTable.Range.Cells(i).Width = oTable.Cell(1, 1).Width And _
oTable.Range.Cells(i).Height = oTable.Cell(1, 1).Height Then
Set oCell = oTable.Range.Cells(i).Range
oCell.End = oCell.End - 1
oCell.FormattedText = oRng
oCell.Collapse 1
oCell.Fields.Add oCell, 41, , False
End If
Next i
oDoc.MailMerge.OpenDataSource sPath
'always use range aa_Loom_Labels as the datasource
oDoc.ActiveWindow.View.ShowFieldCodes = False
oDoc.MailMerge.ViewMailMergeFieldCodes = False
oDoc.MailMerge.Destination = 0
oDoc.MailMerge.Execute Pause:=False
'oWord.Quit False '- This will just clear the merge?
End Sub