I had developed some capacity to modify existing macros in Word – I frequently use a combination of a dozen or so relatively basic VBA macros.
I'm hoping to duplicate them in LibreOffice. I'm just gonna paste the main ones below, in case anyone wants to help out.
In all cases, I'd be applying these functions to the entire document; there'd be no headers/footers or anything like that – I usually clear all formatting within each macro.
If there's somewhere else I should be asking, an automated way to convert them (!), or a comprehensive list of basic equivalents somewhere, please let me know.
Appreciate any help...
1) Remove any formatting and change all text to lower case, Arial font, size 11:
Code: Select all
Selection.WholeStory
Selection.ClearFormatting
Selection.Range.Case = wdLowerCase
Selection.LanguageID = wdEnglishUS
ActiveDocument.Range.Font.Color = wdColorBlack
ActiveDocument.Range.Style = "No Spacing"
ActiveDocument.Range.Font.Name = "Arial"
ActiveDocument.Range.Font.Size = "11"
ActiveDocument.ShowSpellingErrors = True
ActiveDocument.ShowGrammaticalErrors = True
Options.CheckSpellingAsYouType = True
Code: Select all
Dim myStoryRange As Range
For Each myStoryRange In ActiveDocument.StoryRanges
With myStoryRange.Find
.MatchWildcards = False
.Execute findtext:=". ", ReplaceWith:=".^p", Replace:=wdReplaceAll
.Execute findtext:="? ", ReplaceWith:="?^p", Replace:=wdReplaceAll
.Execute findtext:="! ", ReplaceWith:="!^p", Replace:=wdReplaceAll
.Execute findtext:=" # ", ReplaceWith:="^p# ", Replace:=wdReplaceAll
.Execute findtext:=".^034 ", ReplaceWith:=".^034^p", Replace:=wdReplaceAll
.Execute findtext:="?^034 ", ReplaceWith:="?^034^p", Replace:=wdReplaceAll
.Execute findtext:="!^034 ", ReplaceWith:="!^034^p", Replace:=wdReplaceAll
End With
Code: Select all
Dim myStoryRange As Range
For Each myStoryRange In ActiveDocument.StoryRanges
With myStoryRange.Find
.MatchWildcards = False
.Execute findtext:=" ^p", ReplaceWith:="^p", Replace:=wdReplaceAll
.Execute findtext:="^p ", ReplaceWith:="^p", Replace:=wdReplaceAll
.Execute findtext:="^p^p^p", ReplaceWith:="^p^p", Replace:=wdReplaceAll
.Execute findtext:="^p^p^p", ReplaceWith:="^p^p", Replace:=wdReplaceAll
.Execute findtext:="^p^p^p", ReplaceWith:="^p^p", Replace:=wdReplaceAll
End With
Code: Select all
Selection.HomeKey Unit:=wdStory
Dim oSE As Range, oGE As Range
For Each oSE In ActiveDocument.SpellingErrors
oSE.HighlightColorIndex = wdYellow
Next
lbl_Exit:
Exit Sub
End Sub
Code: Select all
Dim oRng As Word.Range
Dim oCol As New Collection
Dim oDoc As Document, lngIndex As Long
Set oRng = ActiveDocument.Range
With oRng.Find
.Highlight = True
While .Execute
oCol.Add oRng.Duplicate
oRng.Collapse wdCollapseEnd
Wend
End With
Set oDoc = Documents.Add
For lngIndex = oCol.Count To 1 Step -1
oDoc.Paragraphs.Last.Range.FormattedText = oCol.Item(lngIndex)
oDoc.Paragraphs.Add
Next
lbl_Exit:
Exit Sub
End Sub
Code: Select all
Dim myStoryRange As Range
For Each myStoryRange In ActiveDocument.StoryRanges
With myStoryRange.Find
.MatchWildcards = True
'change dashes
.Execute FindText:="^0151^13", ReplaceWith:="...^p", Replace:=wdReplaceAll
.Execute FindText:="^0151", ReplaceWith:=" - ", Replace:=wdReplaceAll
.Execute FindText:="^0150", ReplaceWith:=" - ", Replace:=wdReplaceAll
.Execute FindText:=" -^13", ReplaceWith:="...^p", Replace:=wdReplaceAll
'change ellipses
.Execute FindText:="^0133", ReplaceWith:="...", Replace:=wdReplaceAll
.Execute FindText:=" ...^13", ReplaceWith:="...^p", Replace:=wdReplaceAll
.Execute FindText:="^0133", ReplaceWith:="...", Replace:=wdReplaceAll
'change quotes
.Execute FindText:="[^0145^0146]", ReplaceWith:="^039", Replace:=wdReplaceAll
.Execute FindText:="[^0147^0148]", ReplaceWith:="^034", Replace:=wdReplaceAll
'em dashes replaced with hyphen and spaces either side
.Execute FindText:="^0151", ReplaceWith:=" - ", Replace:=wdReplaceAll
'en dashes
.Execute FindText:="([!\-])- ", ReplaceWith:="\1^0150 ", Replace:=wdReplaceAll
.Execute FindText:="^0150", ReplaceWith:="-", Replace:=wdReplaceAll
End With
Code: Select all
Dim myStoryRange As Range
For Each myStoryRange In ActiveDocument.StoryRanges
With myStoryRange.Find
.MatchWildcards = True
.Execute FindText:="[áàâäãå]", ReplaceWith:="a", Replace:=wdReplaceAll
.Execute FindText:="[ÁÀÂÄÃÅ]", ReplaceWith:="A", Replace:=wdReplaceAll
.Execute FindText:="[ç¢]", ReplaceWith:="c", Replace:=wdReplaceAll
.Execute FindText:="[Ç]", ReplaceWith:="C", Replace:=wdReplaceAll
.Execute FindText:="[éèêë]", ReplaceWith:="e", Replace:=wdReplaceAll
.Execute FindText:="[ÉÈÊË]", ReplaceWith:="E", Replace:=wdReplaceAll
.Execute FindText:="[íìîï]", ReplaceWith:="i", Replace:=wdReplaceAll
.Execute FindText:="[ÍÌÎÏ]", ReplaceWith:="I", Replace:=wdReplaceAll
.Execute FindText:="[ñ]", ReplaceWith:="n", Replace:=wdReplaceAll
.Execute FindText:="[Ñ]", ReplaceWith:="N", Replace:=wdReplaceAll
.Execute FindText:="[ðóòôöõø]", ReplaceWith:="o", Replace:=wdReplaceAll
.Execute FindText:="[ÐÓÒÔÖÕØ]", ReplaceWith:="O", Replace:=wdReplaceAll
.Execute FindText:="[úùûü]", ReplaceWith:="u", Replace:=wdReplaceAll
.Execute FindText:="[ÚÙÛÜ]", ReplaceWith:="U", Replace:=wdReplaceAll
.Execute FindText:="[ýÿ]", ReplaceWith:="y", Replace:=wdReplaceAll
.Execute FindText:="[ÝŸ]", ReplaceWith:="Y", Replace:=wdReplaceAll
.Execute FindText:="[š]", ReplaceWith:="s", Replace:=wdReplaceAll
.Execute FindText:="[Š]", ReplaceWith:="S", Replace:=wdReplaceAll
.Execute FindText:="[ž]", ReplaceWith:="z", Replace:=wdReplaceAll
.Execute FindText:="[Ž]", ReplaceWith:="Z", Replace:=wdReplaceAll
.Text = ChrW(256)
.Replacement.Text = "A"
.Execute Replace:=wdReplaceAll
.Text = ChrW(257)
.Replacement.Text = "a"
.Execute Replace:=wdReplaceAll
.Text = ChrW(274)
.Replacement.Text = "E"
.Execute Replace:=wdReplaceAll
.Text = ChrW(275)
.Replacement.Text = "e"
.Execute Replace:=wdReplaceAll
.Text = ChrW(298)
.Replacement.Text = "I"
.Execute Replace:=wdReplaceAll
.Text = ChrW(299)
.Replacement.Text = "i"
.Execute Replace:=wdReplaceAll
.Text = ChrW(332)
.Replacement.Text = "O"
.Execute Replace:=wdReplaceAll
.Text = ChrW(333)
.Replacement.Text = "o"
.Execute Replace:=wdReplaceAll
.Text = ChrW(223)
.Replacement.Text = "ss"
.Execute Replace:=wdReplaceAll
.Text = ChrW(362)
.Replacement.Text = "U"
.Execute Replace:=wdReplaceAll
.Text = ChrW(363)
.Replacement.Text = "u"
.Execute Replace:=wdReplaceAll
.Text = ChrW(562)
.Replacement.Text = "Y"
.Execute Replace:=wdReplaceAll
.Text = ChrW(563)
.Replacement.Text = "y"
.Execute Replace:=wdReplaceAll
End With
Code: Select all
Dim AmountMoved As Long
Dim myRange As Range
'start with first paragraph and extend range down to second
Set myRange = ActiveDocument.Paragraphs(1).Range
AmountMoved = myRange.MoveEnd(Unit:=wdParagraph, Count:=1)
'loop until there are no more paragraphs to check
Do While AmountMoved > 0
'if two paragraphs are identical, delete second one
'and add the one after that to myRange so it can be checked
If myRange.Paragraphs(1).Range.Text = _
myRange.Paragraphs(2).Range.Text Then
myRange.Paragraphs(2).Range.Delete
AmountMoved = myRange.MoveEnd(Unit:=wdParagraph, Count:=1)
Else
'if two paragraphs aren't identical, add the one after
'that to my range, so it can be checked, and drop the first one,
'since it is no longer of interest.
AmountMoved = myRange.MoveEnd(Unit:=wdParagraph, Count:=1)
myRange.MoveStart Unit:=wdParagraph, Count:=1
End If
Loop