1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<!--*********************************************************** 4 * 5 * Licensed to the Apache Software Foundation (ASF) under one 6 * or more contributor license agreements. See the NOTICE file 7 * distributed with this work for additional information 8 * regarding copyright ownership. The ASF licenses this file 9 * to you under the Apache License, Version 2.0 (the 10 * "License"); you may not use this file except in compliance 11 * with the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, 16 * software distributed under the License is distributed on an 17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 * KIND, either express or implied. See the License for the 19 * specific language governing permissions and limitations 20 * under the License. 21 * 22 ***********************************************************--> 23<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. 24' It works on the currently activated document. 25Private const UPPERREPLACECHAR = "X" 26Private const LOWERREPLACECHAR = "x" 27 28Private MSGBOXTITLE 29Private NOTSAVEDTEXT 30Private WARNING 31 32Sub ChangeAllChars ' Change all chars in the active document 33Dim oSheets, oPages as Object 34Dim i as Integer 35Const MBYES = 6 36Const MBABORT = 2 37Const MBNO = 7 38 BasicLibraries.LoadLibrary("Tools") 39 MSGBOXTITLE = "Change All Characters to an '" & UPPERREPLACECHAR & "'" 40 NOTSAVEDTEXT = "This document has already been modified: All characters will be changed to an " & UPPERREPLACECHAR & "'. Should the document be saved now?" 41 WARNING = "This macro changes all characters and numbers to an '" & UPPERREPLACECHAR & "' in this document." 42 43 On Local Error GoTo NODOCUMENT 44 oDocument = StarDesktop.ActiveFrame.Controller.Model 45 NODOCUMENT: 46 If Err <> 0 Then 47 Msgbox(WARNING & chr(13) & "First, activate a Writer document." , 16, GetProductName()) 48 Exit Sub 49 End If 50 On Local Error Goto 0 51 52 sDocType = GetDocumentType(oDocument) 53 54 If oDocument.IsModified And oDocument.Url <> "" Then 55 Status = MsgBox(NOTSAVEDTEXT, 3+32, MSGBOXTITLE) 56 Select Case Status 57 Case MBYES 58 oDocument.Store 59 Case MBABORT, MBNO 60 End 61 End Select 62 Else 63 Status = MsgBox(WARNING, 3+32, MSGBOXTITLE) 64 If Status = MBNO Or Status = MBABORT Then ' No, Abort 65 End 66 End If 67 End If 68 69 Select Case sDocType 70 Case "swriter" 71 ReplaceAllStrings(oDocument) 72 73 Case Else 74 Msgbox("This macro only works with Writer documents.", 16, GetProductName()) 75 End Select 76End Sub 77 78 79Sub ReplaceAllStrings(oContainer as Object) 80 ReplaceStrings(oContainer, "[a-z]", LOWERREPLACECHAR) 81 ReplaceStrings(oContainer, "[à-þ]", LOWERREPLACECHAR) 82 ReplaceStrings(oContainer, "[A-Z]", UPPERREPLACECHAR) 83 ReplaceStrings(oContainer, "[À-ß]", UPPERREPLACECHAR) 84 ReplaceStrings(oContainer, "[0-9]", UPPERREPLACECHAR) 85End Sub 86 87 88Sub ReplaceStrings(oContainer as Object, sSearchString, sReplaceString as String) 89 oReplaceDesc = oContainer.createReplaceDescriptor() 90 oReplaceDesc.SearchCaseSensitive = True 91 oReplaceDesc.SearchRegularExpression = True 92 oReplaceDesc.Searchstring = sSearchString 93 oReplaceDesc.ReplaceString = sReplaceString 94 oReplCount = oContainer.ReplaceAll(oReplaceDesc) 95End Sub</script:module> 96