![]() |
|
#1
|
|||
|
|||
|
I working on different references styles.
Kindly help. If two names insert and before last name. End dot before last name highlighted in yellow. and explain how to use not [!]. |
|
#2
|
||||
|
||||
|
Some of your paragraphs have one name and some more than two. The following will replace the last comma where appropriate with 'and'.
The '!' character is not required here, but see Replace using wildcards Code:
Sub Macro1()
Dim oPara As Paragraph
Dim oRng As Range, oLink As Range
Dim i As Long, j As Long, k As Long, m As Long
Dim vPara As Variant
Dim sText As String
For i = 1 To ActiveDocument.Paragraphs.Count
Set oRng = ActiveDocument.Paragraphs(i).Range
oRng.End = oRng.End - 1
sText = ""
vPara = Split(oRng.Text, Chr(44))
j = UBound(vPara) - 1
For k = 0 To j - 1
sText = sText & vPara(k)
If k < j - 1 Then sText = sText & Chr(44)
Next k
If j = 0 Then
sText = vPara(j) & Chr(44)
Else
sText = sText & " and" & vPara(j) & Chr(44)
End If
Set oLink = ActiveDocument.Paragraphs(i).Range
oLink.End = oLink.End - 1
m = InStrRev(oLink, Chr(44))
oLink.MoveStart wdCharacter, m
oLink.Copy
oRng.Text = sText
oRng.Collapse 0
oRng.Paste
Next i
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Convert manual cross references in footnotes to other footnotes to automatic cross references | ghumdinger | Word VBA | 7 | 11-20-2014 11:47 PM |
Kindly repair these .docx file
|
alexcj37 | Word | 1 | 02-07-2014 08:25 PM |
Section references in a multilevel list
|
Crumbar | Word | 2 | 02-24-2013 01:26 PM |
Kindly help me answer these questions
|
Twene | Excel | 1 | 11-20-2011 02:18 AM |
kindly fix my problem its urgent!
|
SyedaAdil | Office | 1 | 11-04-2009 08:15 AM |