1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="ChangeAllChars" script:language="StarBasic">' This macro replaces all characters in a writer-documet through "x" or "X" signs. 4' It works on the currently activated document. 5Private const UPPERREPLACECHAR = "X" 6Private const LOWERREPLACECHAR = "x" 7 8Private MSGBOXTITLE 9Private NOTSAVEDTEXT 10Private WARNING 11 12Sub ChangeAllChars ' Change all chars in the active document 13Dim oSheets, oPages as Object 14Dim i as Integer 15Const MBYES = 6 16Const MBABORT = 2 17Const MBNO = 7 18 BasicLibraries.LoadLibrary("Tools") 19 MSGBOXTITLE = "Change All Characters to an '" & UPPERREPLACECHAR & "'" 20 NOTSAVEDTEXT = "This document has already been modified: All characters will be changed to an " & UPPERREPLACECHAR & "'. Should the document be saved now?" 21 WARNING = "This macro changes all characters and numbers to an '" & UPPERREPLACECHAR & "' in this document." 22 23 On Local Error GoTo NODOCUMENT 24 oDocument = StarDesktop.ActiveFrame.Controller.Model 25 NODOCUMENT: 26 If Err <> 0 Then 27 Msgbox(WARNING & chr(13) & "First, activate a Writer document." , 16, GetProductName()) 28 Exit Sub 29 End If 30 On Local Error Goto 0 31 32 sDocType = GetDocumentType(oDocument) 33 34 If oDocument.IsModified And oDocument.Url <> "" Then 35 Status = MsgBox(NOTSAVEDTEXT, 3+32, MSGBOXTITLE) 36 Select Case Status 37 Case MBYES 38 oDocument.Store 39 Case MBABORT, MBNO 40 End 41 End Select 42 Else 43 Status = MsgBox(WARNING, 3+32, MSGBOXTITLE) 44 If Status = MBNO Or Status = MBABORT Then ' No, Abort 45 End 46 End If 47 End If 48 49 Select Case sDocType 50 Case "swriter" 51 ReplaceAllStrings(oDocument) 52 53 Case Else 54 Msgbox("This macro only works with Writer documents.", 16, GetProductName()) 55 End Select 56End Sub 57 58 59Sub ReplaceAllStrings(oContainer as Object) 60 ReplaceStrings(oContainer, "[a-z]", LOWERREPLACECHAR) 61 ReplaceStrings(oContainer, "[à-þ]", LOWERREPLACECHAR) 62 ReplaceStrings(oContainer, "[A-Z]", UPPERREPLACECHAR) 63 ReplaceStrings(oContainer, "[À-ß]", UPPERREPLACECHAR) 64 ReplaceStrings(oContainer, "[0-9]", UPPERREPLACECHAR) 65End Sub 66 67 68Sub ReplaceStrings(oContainer as Object, sSearchString, sReplaceString as String) 69 oReplaceDesc = oContainer.createReplaceDescriptor() 70 oReplaceDesc.SearchCaseSensitive = True 71 oReplaceDesc.SearchRegularExpression = True 72 oReplaceDesc.Searchstring = sSearchString 73 oReplaceDesc.ReplaceString = sReplaceString 74 oReplCount = oContainer.ReplaceAll(oReplaceDesc) 75End Sub</script:module>