Please note the USER VARIABLE "AskMe" near the beginning of the file which controls whether you are asked about doing each of the operations.
Also note that my definition of the AskArray extends over several lines by using "_" to continue the definition to the next line. "_" must be the last character on the line and if is followed inadvertently by a space you will get an error.
- Code: Select all Expand viewCollapse view
Option Explicit 'You must Dim all variables.
Dim AskMe as Boolean
AskMe = True 'Change to False to avoid the query for each find & replace.
'>>>>>>>>>>END USER VARIABLE<<<<
AskArray = Array("Replace multiple spaces with one space?",_
"Delete spaces before paragraph breaks?",_
"Delete spaces before tabs?",_
"Delete spaces after tabs?")
REM Place in quotes what you would put in the Search/Replace boxes
REM in the Find & Replace dialog without the quotes.
SearchArray = Array(" *"," *$"," *\t","\t *")
ReplaceAray = Array(" " ,"" ,"\t" ,"\t" )
oDoc = ThisComponent 'Get the current active document.
FandR = oDoc.createReplaceDescriptor 'Set up find & replace.
FandR.searchRegularExpression = True 'Make it recognise regular expressions.
For c = 0 to uBound(SearchArray) 'Loop through the arrays.
If AskMe then 'If AskMe is True then ask.
iAns = MsgBox (AskArray(c),3)'See Help in the Basic IDE for the various
'buttons available in MsgBox and the integers they return.
If iAns = 2 then End 'Cancel button clicked so quit.
IF iAns = 6 or AskMe = False then 'Yes button clicked, or assumed clicked,
'so do the find & replace.
'The No button will simple fall through to here so there is no need to process it.