Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-27-2016, 07:51 AM
Formd Formd is offline Using SEQ in VBA Windows 7 32bit Using SEQ in VBA Office 2007
Advanced Beginner
Using SEQ in VBA
 
Join Date: Feb 2015
Location: TX
Posts: 46
Formd is on a distinguished road
Question Using SEQ in VBA

I have what could be a complicated issue and hope you can assist.
I want to loop a paragraph based on user input and change fields at the same time. You are probably asking, "say what??"



Here is my paragraph
The Defendant, {MERGEFIELD Defendant_1} cannot afford to pay for an attorney, however legal advice may be available by contacting.............
Here are my field names in the database
Defendant_1
Defendant_2
Defendant_3
Defendant_4
Defendant_5 and so on.

If user selects 3 from a dropdown list, how do I get the numbers at the end of each mergefield to change on each loop? I believe SEQ does the trick but how (in VBA)? Here is a macro I recorded with attempts to use in vba but it does not work. Forgive me but I am still an ametuer who tries.

Here is what I used in VBA
If Cbodef.ListIndex = 3 Then 'Cbodef is the name used in vba form field
Selection.GoTo What:=wdGoToBookmark, Name:="Defendants"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
Cbodef = 0
Do While cbodef < 4
Selection.TypeText Text:="The Defendant "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"MERGEFIELD Defendant_ ", PreserveFormatting:=True
Selection.MoveLeft Unit:=wdCharacter, Count:=18
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"SEQ \* Arabic", PreserveFormatting:=True
Selection.TypeText Text:=" cannot afford to pay for an attorney, however "
Selection.TypeText Text:="legal advice may be available by contacting T "
Selection.TypeText Text:="he Clerk's office."
Cbodef = Cbodef + 1
Loop
Thanks in advance for your help.
I am using Word 2007
Reply With Quote
  #2  
Old 07-27-2016, 09:24 PM
gmayor's Avatar
gmayor gmayor is offline Using SEQ in VBA Windows 10 Using SEQ in VBA Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

This is a many to one mail merge. It might save a lot of grief if you investigated http://www.gmayor.com/ManyToOne.htm otherwise see https://www.msofficeforums.com/mail-...ps-tricks.html
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



Other Forums: Access Forums

All times are GMT -7. The time now is 08:47 PM.


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