Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-04-2024, 11:46 AM
WizKidd WizKidd is offline How to Insert all merge fields into a blank document Windows 11 How to Insert all merge fields into a blank document Office 2021
Novice
 
Join Date: Nov 2024
Posts: 1
WizKidd is on a distinguished road
Arrow Corrective Tweak

Quote:
Originally Posted by gmayor View Post
It is difficult to understand the point of this, but the following macro will work, provided you attach the datasource to the blank document:
Code:
Sub Macro1()
Dim i As Integer
Dim orng As Range
    With ActiveDocument.MailMerge.DataSource
        For i = 1 To .FieldNames.Count
            Set orng = ActiveDocument.Range
            orng.Collapse 0
            orng.Fields.Add orng, wdFieldMergeField, Chr(34) & .FieldNames(i), False
            Set orng = ActiveDocument.Range
            orng.Collapse 0
            orng.InsertParagraphAfter
        Next i
    End With
    Set orng = Nothing
End Sub
When I ran this, each field name had a space at the end, which didn't match my DataSource (e.g.: «NO_OF_DAYS ») so I removed just the "Chr(34) & " from line 8, then they came out correctly («NO_OF_DAYS»).



Thanks!

P.S.: WOW, I haven't used BBCode in ages!
Reply With Quote
Reply

Tags
insert all merge fields



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Insert all merge fields into a blank document Mail merge all fields into 1 document with rules MP1989 Mail Merge 6 06-27-2018 04:43 PM
How to Insert all merge fields into a blank document insert blank page in document Patryk Word VBA 1 01-22-2016 03:11 AM
insert fields mail merge in vba tariqaleed2 Word VBA 6 08-21-2014 12:21 AM
How to Insert a Clear, Blank page without Lines and Numbers in a Pleading Document Dirigo Word 5 09-30-2011 08:08 AM
delete blank pages from mail merge document blusea Word 0 12-17-2010 06:10 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:06 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft