#1
|
|||
|
|||
Expand scripture references
I have a Word document that has many scripture references such as: Ps 23:1-3; 148:5,6; 150:2; Isa 5:2,5,7; Rev 2:3; 22:5 I need these fully expanded to: Ps 23:1-3; Ps 148:5; Ps 148:6; Ps 150:2; Isa 5:2; Isa 5:5; Isa 5:7; Rev 2:3; Rev 22:5 I would really appreciate any help. Last edited by WJSwanepoel; 02-09-2023 at 02:28 AM. Reason: Refined question |
#2
|
||||
|
||||
The second list contains more items than the first, but as far as the first list goes, select the list then run the following macro:
Code:
Sub FixSelectedReferences() Dim vList As Variant, vItem As Variant Dim i As Integer, j As Integer Dim oDoc As Document, oTmp As Document vList = Split(Selection.Text, ";") Set oDoc = ActiveDocument Set oTmp = Documents.Add For i = 0 To UBound(vList) vItem = Split(vList(i), ",") For j = 0 To UBound(vItem) oTmp.Range.InsertAfter Trim(vItem(j)) If j < UBound(vItem) Then oTmp.Range.InsertParagraphAfter Next j If i < UBound(vList) Then oTmp.Range.InsertParagraphAfter Next i Selection.Text = FixList(oTmp) lbl_Exit: Set oDoc = Nothing Set oTmp = Nothing Exit Sub End Sub Private Function FixList(oTmp As Document) As String Dim oPara As Paragraph Dim oRng As Range Dim i As Integer Dim sRef As String For i = 1 To oTmp.Range.Paragraphs.Count Set oPara = oTmp.Range.Paragraphs(i) Set oRng = oPara.Range oRng.Collapse (1) If IsNumeric(Left(oPara.Range, 1)) = False Then oRng.MoveEndUntil Chr(32) sRef = oRng.Text & Chr(32) Else oRng.Text = sRef End If Next i Set oRng = oTmp.Range With oRng.Find .Text = "^p" .Replacement.Text = "; " .Execute Replace:=wdReplaceAll End With Set oRng = oTmp.Paragraphs(1).Range oRng.End = oRng.End - 3 FixList = oRng.Text oTmp.Close 0 lbl_Exit: Set oRng = Nothing Set oPara = Nothing Exit Function End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Need more than this
Sorry,
I was not very clear in my requirements. My document does not only contains these list of Scripture references. They are contained in various places within a rather large document. and do not necessarily start on a new line. What I need is a macro that will process the entire document looking for Scripture references and fixing any "incomplete" references. One will therefore probably need an array which keeps all the bookname abbreviations? |
#4
|
||||
|
||||
Good luck with that.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
Tags |
scripture, vba |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
collapse and expand | mswmacroman | Word | 2 | 12-10-2018 06:52 PM |
Putting 3 verses of scripture into a Word doc | oldyeller1938 | Word | 1 | 05-14-2018 03:35 AM |
Scripture Index | WJSwan | Word VBA | 5 | 03-31-2018 02:35 AM |
Convert manual cross references in footnotes to other footnotes to automatic cross references | ghumdinger | Word VBA | 7 | 11-20-2014 11:47 PM |
Grouping - expand all | ejohns | Excel | 0 | 07-17-2009 07:15 AM |