2012/7/17 Johnny Rosenberg <[email protected]>:
> 2012/7/17 Srinivasulu Bhattaram <[email protected]>:
>> I am new to Open Office.
>> InWORD 2003 (and also in WORD 2007),
>> I have craeted macros to remove double spaces with single spaces and used
>> them extensively..
>> How to have an equivalent of it in Open Office writer?
>>
>> I do not want to go through   Find    Replace.... kind of thing.
>> seena
>
> What about letting a macro do the search and replace for you?
>
> I just wrote this one, with inspiration from ”Useful Macro Information
> For OpenOffice.org By Andrew Pitonyak”, which is a PDF that you can
> download somewhere:
>
> REM  *****  BASIC  *****
>
> Sub RemoveRedundantSpaces
>         Dim oReplace as object
>         oReplace = ThisComponent.createReplaceDescriptor()
>
>         With oReplace
>                 .SearchString = "  "
>                 .ReplaceString = " "
>         End With
>
>         While ThisComponent.ReplaceAll(oReplace)>0
>         Wend
> End Sub

I made some changes to the macro, which now will tell you how many
spaces were removed:

REM  *****  BASIC  *****

Option Explicit

Sub RemoveRedundantSpaces
        Dim oReplace as object
        oReplace = ThisComponent.createReplaceDescriptor()

        With oReplace
                .SearchString = "  "
                .ReplaceString = " "
        End With

        Dim Count As Integer, TotalCount As Integer
        Do
                Count=ThisComponent.ReplaceAll(oReplace)
                TotalCount=TotalCount+Count
        Loop While Count>0
        
        Select Case TotalCount
        Case 0
                Print "No redundant spaces found."
        Case 1
                Print "1 space was removed."
        Case Else
                Print TotalCount & " spaces were removed."
        End Select
End Sub


>
>
> This macro also takes care of tripple spaces and… well, it just
> removes all spaces until there are only single spaces left. And it is
> fast. Really fast.
> I tested it myself, and it worked in all my test cases. Well, I didn't
> test it THAT thoroughly, but still…
>
> Much better than using the crappy macro recorder anyway. And shorter…
>
> If you write the documents yourself, there is a simple way to prevent
> double spaces in the first place, something like:
> Tools → Options for auto correction… → Click the Options tab → ☒
> Ignore double spaces
>
> You can still make double spaces if you really want to, but it's less
> likely to happen accidently.
>
>
> Kind regards
>
> Johnny Rosenberg
> ジョニー・ローゼンバーグ

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to