Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-08-2023, 08:56 PM
WJSwanepoel WJSwanepoel is offline Expand scripture references Windows 10 Expand scripture references Office 2021
Advanced Beginner
Expand scripture references
 
Join Date: Dec 2019
Location: Krugersdorp, South Africa
Posts: 65
WJSwanepoel is on a distinguished road
Question 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
Reply With Quote
  #2  
Old 02-11-2023, 04:01 AM
gmayor's Avatar
gmayor gmayor is offline Expand scripture references Windows 10 Expand scripture references Office 2019
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

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
Reply With Quote
  #3  
Old 02-12-2023, 10:01 PM
WJSwanepoel WJSwanepoel is offline Expand scripture references Windows 10 Expand scripture references Office 2021
Advanced Beginner
Expand scripture references
 
Join Date: Dec 2019
Location: Krugersdorp, South Africa
Posts: 65
WJSwanepoel is on a distinguished road
Default 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?
Reply With Quote
  #4  
Old 02-13-2023, 03:57 AM
gmayor's Avatar
gmayor gmayor is offline Expand scripture references Windows 10 Expand scripture references Office 2019
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

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
Reply With Quote
Reply

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
Expand scripture references 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

Other Forums: Access Forums

All times are GMT -7. The time now is 08:45 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