Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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: 49
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
 



Other Forums: Access Forums

All times are GMT -7. The time now is 04:56 AM.


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