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