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">&apos; This macro replaces all characters in a writer-documet through &quot;x&quot; or &quot;X&quot; signs.
4&apos; It works on the currently activated document.
5Private const UPPERREPLACECHAR = &quot;X&quot;
6Private const LOWERREPLACECHAR = &quot;x&quot;
7
8Private MSGBOXTITLE
9Private NOTSAVEDTEXT
10Private WARNING
11
12Sub ChangeAllChars   &apos; 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(&quot;Tools&quot;)
19	MSGBOXTITLE = &quot;Change All Characters to an &apos;&quot; &amp; UPPERREPLACECHAR &amp; &quot;&apos;&quot;
20	NOTSAVEDTEXT = &quot;This document has already been modified: All characters will be changed to an &quot; &amp; UPPERREPLACECHAR &amp; &quot;&apos;. Should the document be saved now?&quot;
21	WARNING = &quot;This macro changes all characters and numbers to an &apos;&quot; &amp; UPPERREPLACECHAR &amp; &quot;&apos; in this document.&quot;
22
23	On Local Error GoTo NODOCUMENT
24	oDocument = StarDesktop.ActiveFrame.Controller.Model
25	NODOCUMENT:
26	If Err &lt;&gt; 0 Then
27		Msgbox(WARNING &amp; chr(13) &amp; &quot;First, activate a Writer document.&quot; , 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 &lt;&gt; &quot;&quot; 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  &apos; No, Abort
45			End
46		End If
47	End If
48
49	Select Case sDocType
50		Case &quot;swriter&quot;
51			ReplaceAllStrings(oDocument)
52
53		Case Else
54			Msgbox(&quot;This macro only works with Writer documents.&quot;, 16, GetProductName())
55	End Select
56End Sub
57
58
59Sub ReplaceAllStrings(oContainer as Object)
60	ReplaceStrings(oContainer, &quot;[a-z]&quot;, LOWERREPLACECHAR)
61	ReplaceStrings(oContainer, &quot;[à-þ]&quot;, LOWERREPLACECHAR)
62	ReplaceStrings(oContainer, &quot;[A-Z]&quot;, UPPERREPLACECHAR)
63	ReplaceStrings(oContainer, &quot;[À-ß]&quot;, UPPERREPLACECHAR)
64	ReplaceStrings(oContainer, &quot;[0-9]&quot;, 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>