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