Mail Merge in Word (Sort of)

chipsworld

Board Regular
Joined
May 23, 2019
Messages
164
Office Version
  1. 365
I have created a Mail Merge form that we use here at work, but one field is a "Control Number" which has four parts.

Part one: Year signifier
Part two: Julian Date (day of year)
Part three: Number (001, 002, 003, 004, etc)
Part four: Unit # (Military)

What I am trying to do is write a VBA Function that will allow the user to enter the Unit name and the Date (auto generate the Julian, which I have figured out), and then incorporate the Merge Field (number) into a single string. THis is not as easy as I thought it would be.

I can do all of the parts except for the MergeField...

How can I incorporate a MergeField into the String for the Control Number?

The end result should look like the below:

1st BN, 75th INF
U20 - 217 - 001

Here is what I have so far, but as you can probably guess, it doesn't work. Can't get past this MergeField thing...

VBA Code:
Private Sub Document_Open()
Dim MyValue As String
Dim Julian As String
Dim jdate As String
Dim ifField As MailMergeField
Set ifField = ActiveDocument.MailMerge.Fields.AddIf(Range:=Selection.Range, MergeField:= _
"NUM"), Comparison:=wdMergeIfNotEqual, CompareTo:="", TrueText:="FieldIfTrue", _
FalseText:="FieldIfFalse")

MyValue = InputBox("Enter the Unit Name", "Enter Control Number Info", "")
Julian = InputBox("Enter the Julian Date", "JULIAN DATE", "")

jdate = DateDiff("d", DateSerial(Year(Julian) - 1, 12, 31), Julian)

Me.CNTRLINPUT.Text = MyValue & vbCr & "U20 - " & jdate & " - " & ifField


End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Anyone have any ideas? Maybe I am approaching the process wrong? I know someone on here knows how to do this...
 
Upvote 0

Forum statistics

Threads
1,223,641
Messages
6,173,506
Members
452,518
Latest member
SoerenB

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