how to propagate label fields in word Mail Merge from Excel

bulevardi

Board Regular
Joined
Apr 21, 2011
Messages
69
I want to make a mail merge for labels.
I want it to run from my excel application.

I know already that it's better to open a word document that runs a word macro that makes the labels.
But instead, I need my excel macro creating a new word doc with the labels inside.

It works already fine, except to propagate the fields in every label. I tried it with
Code:
For c = 1 To .mailmerge.Fields.Count
      .mailmerge.Fields.Add Range:=Selection.Range.Fields(c), Type:=wdFieldMergeField, Text:="""Naam"""
      .mailmerge.Fields.Update
    Next c
But apparently, when I open the word doc afterwards, it isn't filled with the fields, and I have to do it manually again myself.

Can someone help with this?
Or does someone have a working example?

Code:
Sub mailmerge()

MsgBox "mailmerge is working"
 
Dim appWD As Object 
Dim etiketten As String
etiketten = "C:\myfolder\mylabels.doc"
 
Dim strThisWorkbook As String
strThisWorkbook = ThisWorkbook.FullName
 
If appWD Is Nothing Then
 Set appWD = CreateObject("Word.Application")
End If
    
appWD.Visible = True
Set wrdDoc = appWD.Documents.Add
With wrdDoc
    .SaveAs (etiketten)
    .Activate
End With
With wrdDoc
 .mailmerge.MainDocumentType = wdMailingLabels
 .mailmerge.OpenDataSource ThisWorkbook.FullName, , , , , , , , , , , "Data Source=" & strThisWorkbook & ";Mode=Read", "SELECT * FROM `Temp$`"
 .mailmerge.ViewMailMergeFieldCodes = wdToggle

' somewhere here, the script does not propagate the fields in the word  document 
    For c = 1 To .mailmerge.Fields.Count
      .mailmerge.Fields.Add Range:=Selection.Range.Fields(c), Type:=wdFieldMergeField, Text:="""Naam"""
      .mailmerge.Fields.Update
    Next c
    
End With
 
With wrdDoc
    .SaveAs (etiketten)
End With

Set wrdDoc = Nothing
appWD.Quit
Set appWD = Nothing
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
When I reopen the word document later on aswel.
He doesn't open it as a labels type document, but as the default word document.
 
Upvote 0

Forum statistics

Threads
1,223,276
Messages
6,171,140
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top