home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2002 October / VPR0210A.ISO / OPENOFFICE / f_0187 / ChangeAllChars.xba < prev    next >
Extensible Markup Language  |  2001-10-08  |  3KB  |  75 lines

  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.
  5. Private const UPPERREPLACECHAR = "X"
  6. Private const LOWERREPLACECHAR = "x"
  7.  
  8. Private MSGBOXTITLE
  9. Private NOTSAVEDTEXT
  10. Private WARNING
  11.  
  12. Sub ChangeAllChars   ' Change all chars in the active document
  13. Dim oSheets, oPages as Object
  14. Dim i as Integer
  15. Const MBYES = 6
  16. Const MBABORT = 2
  17. Const 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
  56. End Sub
  57.  
  58.  
  59. Sub 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)
  65. End Sub
  66.  
  67.  
  68. Sub 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)
  75. End Sub</script:module>