[Solved] createSearchDescriptor Does Not Work

Creating a macro - Writing a Script - Using the API

[Solved] createSearchDescriptor Does Not Work

Postby Robitron » Thu Mar 22, 2018 11:05 pm

Okay, I copied and pasted this example taken from https://wiki.openoffice.org/wiki/Docume ... ity_Search
Here is the example:

Code: Select all   Expand viewCollapse view
Sub Test
Dim SearchDesc As Object
Dim Doc As Object

Doc = ThisComponent
SearchDesc = Doc.createSearchDescriptor
SearchDesc.SearchString="turnover"
SearchDesc.SearchSimilarity = True
SearchDesc.SearchSimilarityAdd = 2
SearchDesc.SearchSimilarityExchange = 2
SearchDesc.SearchSimilarityRemove = 2
SearchDesc.SearchSimilarityRelax = False
Found = Doc.findFirst (SearchDesc)

Do Until IsNull(Found)
  Found.CharWeight = com.sun.star.awt.FontWeight.BOLD
  Found = Doc.findNext( Found.End, SearchDesc)
Loop
End Sub


Here is the error:

Screenshot (21).png


So is this outdated or is there something else I'm missing?

What I am looking to do is set up a code that will search the contents of the cell and determine if it contains a phrase regardless of capitalization. So if this is outdated, could someone point me in a good direction to achieve this end? Thanks.
Last edited by robleyd on Fri Mar 23, 2018 1:16 am, edited 2 times in total.
Reason: Add green tick [robleyd, Moderator]
OpenOffice 4.1.5 on Windows 10

What am I doing here? What are you doing here? Wait, where are we?
Robitron
 
Posts: 91
Joined: Thu Nov 15, 2012 5:27 pm

Re: createSearchDescriptor Does Not Work

Postby JeJe » Thu Mar 22, 2018 11:24 pm

That macro is for a text document and won't work in a spreadsheet document. If you do a search here or google openoffice search contents of cell you should get something for a spreadsheet
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 458
Joined: Wed Mar 09, 2016 2:40 pm

Re: createSearchDescriptor Does Not Work

Postby Robitron » Fri Mar 23, 2018 12:07 am

JeJe wrote:That macro is for a text document and won't work in a spreadsheet document. If you do a search here or google openoffice search contents of cell you should get something for a spreadsheet


Wow, how did I miss that? lol Thanks. I acutally found the UCase and LCase functions so I just converted the text in the cell to lowercase with the RType = LCase(Cell1.String) and used the Select Case option to put it right.

At least it's doable but if I had several options, it would be a bit much to set up the Select Case for all of them. Fortunately, there are only two choices for this cell that are acceptable.
OpenOffice 4.1.5 on Windows 10

What am I doing here? What are you doing here? Wait, where are we?
Robitron
 
Posts: 91
Joined: Thu Nov 15, 2012 5:27 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 4 guests