So years ago I was helped by three legends on this forum:
@Charles Kenyon
@Guessed
@gmayor
They helped me by making macros that I had (and still have) no idea how to make, and I am grateful for them and all the time those macros have saved me in my creative writing projects. Well, now I’m in a similar situation as before.
While I don’t want to part ways with my beloved Word 2003, I know I can't keep using it forever. So I have to switch over to something more future-proof, and I've chosen LibreOffice. The problem is the Word macros won’t work on LO because they have different coding languages. I actually posted in the LibreOffice forums about it, but I figured I’d ask here too just in case someone can help here before someone can help over there.
My question is "Are there any LibreOffice macro experts in the house?"
If not, that’s okay. I’m literally on a Word forum, which has nothing to do with LibreOffice so that's my own dang fault.
If the answer is yes, I have another question for ya:
Are you badass enough to convert these Word macros into LO ones??
(Because I can’t. I have no idea what I’m doing over here, haha.)
So here is the first Word macro, which makes so you can search a keyword and it’ll send all paragraphs containing those keywords to a new document that opens up:
Code:
Sub TheNewMagicTimeSaver()
Dim oDoc As Document
Dim oRng As Range
Dim strKeyWord As String
strKeyWord = InputBox("What are you looking for?")
If strKeyWord = "" Then GoTo lbl_Exit
Set oRng = ActiveDocument.Range
Set oDoc = Documents.Add
With oRng.Find
Do While .Execute(FindText:=strKeyWord, MatchCase:=False, MatchWholeWord:=True)
oDoc.Range.InsertAfter oRng.Paragraphs(1).Range.FormattedText
oDoc.Range.InsertParagraphAfter
oRng.Paragraphs(1).Range.Delete
oRng.Collapse 0
Loop
End With
oDoc.Range.ParagraphFormat.SpaceBefore = 0
oDoc.Range.ParagraphFormat.SpaceAfter = 0
lbl_Exit:
Exit Sub
End Sub
And here is the second Word macro, which takes all paragraphs and automatically arranges them from biggest to smallest.
Code:
Sub SortParasBySize()
Dim aRng As Range, aTable As Table, aRow As Row
ActiveWindow.View = wdNormalView
With ActiveDocument.Range.Find 'Do Find and Replace for separators
.ClearFormatting
.Replacement.ClearFormatting
.Text = "^p"
.Replacement.Text = "zx"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
.Text = "zxzx"
.Replacement.Text = "^p"
.Execute Replace:=wdReplaceAll
ActiveDocument.Range.ConvertToTable Separator:=wdSeparateByParagraphs, NumColumns:=1
.Text = "zx"
.Replacement.Text = "^p"
.Execute Replace:=wdReplaceAll
End With
Set aTable = ActiveDocument.Tables(1)
aTable.Columns.Add BeforeColumn:=aTable.Columns(1)
For Each aRow In aTable.Rows
aRow.Cells(1).Range.Text = Len(aRow.Cells(2).Range.Text)
Next aRow
aTable.Rows.Add BeforeRow:=aTable.Rows(1)
aTable.SortDescending
aTable.Columns(1).Delete
aTable.Columns.Add 'insert empty column to reinstate extra paras between sections
aTable.Rows(1).Delete
aTable.ConvertToText Separator:=wdSeparateByParagraphs
End Sub
Thank you for any help, and I apologize for still not knowing how this stuff works. I am but a simple man.