El lun, 05-06-2006 a las 21:35 -0400, Andrew Douglas Pitonyak escribió: > Miguel Quirós wrote: > > >Hello. I am not sure if I am sending this message to the proper place. > >In this case, I would be grateful for a reply telling me which this > >proper place may be. > > > > > Anthony already indicated the best place to ask this question... > > >I wrote a macro for OpenOffice 1.1.4 that used a sentence like the > >following: > > encontrado = dispatcher.executeDispatch(document, > >".uno:ExecuteSearch", "", 0, busqueda()) > >to perform a text search in a document and get a boolean value (stored > >in the boolean variable encontrado) to check whether the search was > >successful or not. > > > > > You are using the dispatcher, which works, but is more likely to change > than using regular API calls. > >Could anyone tell me which kind of value (if any!) is returned by this > >procedure in OpenOffice 2.0? How can I get now the boolean value I used > >to get in Open Office 1.1? > > > > > I do not believe that this is really the best way to do this. When I > want to know what is returned, I usually end up looking at hte source > code, which is a very difficult thing to do (so I recommend against it). > If you obtained the macro using the macro recorder, perhaps you can > record the macro again. Otherwise, perhaps you can modify an existing > API example that is less likely to change. If all that you want to do is > to see if some text exists, then the following might work for you. > > Dim vDescriptor, vFound > ' Create a descriptor from a searchable document. > vDescriptor = ThisComponent.createSearchDescriptor() > ' Set the text for which to search and other > ' > http://api.openoffice.org/docs/common/ref/com/sun/star/util/SearchDescriptor.html > > > With vDescriptor > .SearchString = "hello" > ' These all default to false so you can comment them if you do > ' not want them... > .SearchWords = true > .SearchCaseSensitive = False > End With > ' Find the first one > vFound = ThisComponent.findFirst(vDescriptor) > ' At this point, all you seemed to want to know was if it existed or not > ' Note, however, that the search as shown is from the START of the > ' document. > If IsNull(vFound) Then > Print "The text did NOT exist" > Else > Print "The text did exist and was found" > End If > > If you set the variable "cursor" to something first, you should be able > to use "ThisComponent.findNext(cursor, vDescriptor)" to start from a > different location than the start. >
Thank you very much for your answer. As I told, I am not expert in writing macros and I am just using the things that I can see are used by the macro recorder (the dispatcher) and try to adapt them to my needs. >From your answer, I deduce that there are methods easier to use than the dispatcher (.searchString). My needs are to search all occurrences of a determinate string in a document and, in some cases just replace it by another simple string (in which case I see that there is something called .replaceAll that may be useful and easy to use) and in other cases by something more complicated like putting a new string with special symbols, superindexes , etc in it, in this case perhaps .replaceAll cannot do all the work. As suggested, I am sending this message also to [email protected] -- Miguel Quirós Olozábal Departamento de Química Inorgánica. Facultad de Ciencias. Universidad de Granada. 18071 Granada. SPAIN email:mquiros<at>ugr<dot>es mquiros<arroba>ugr<punto>es --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
