Need simple find & replace macro

I want to migrate my law office from WordPerfect to Libreoffice. My forms
have the } character that I use where I want to input text. I created a
macro in WordPerfect that searches for that character, deletes it, and
leaves the cursor at the position. I've assigned the macro to a key so I
can quickly go through documents.

I'm having difficulty learning how to duplicate this in Libreoffice.
Likewise, I'm having difficulty finding one that already does this.

Help please. Thanks.

Paul

Hi :slight_smile:
I found this link
http://www.gmccomb.com/vbafaq.html

Apparently the language that WordPerfect uses for macros is "Microsoft VBA" so it's likely to need to be 'translated' into LibreOffice Basic or something.  There seem to be 4 options for macro language in LO, see
Tools - Macros - "Organise Macros"

Hmm, now i see the wikipedia page says it uses "PerfectScript macro language" which is also likely to need to be 'translated'.  I liked the line  ...
"WordPerfect macros ... are not embedded in a document. As a result, WordPerfect is not prone to macro viruses or malware, unlike MS Word. "
but i get the impression that LO macros are also less likely to get infected but for some other reasons.

If you post the code here or to the devs list there might be someone that is interested in having a go at translating to LO.  There are some awesome people here that are often good like that.

Regards from
Tom :slight_smile:

Tom:

Thanks for the response.

Don't overthink this. I'm not trying to convert anything from WordPerfect.
Rather, I'm trying to just write one for use in Libreoffice (or purloin one
someone else has written).

The Libreoffice documents will have the } character. I want a macro to find
that character, delete it, and leave the cursor at that position. It needs
to be one I can assign to a key.

Paul

Well, that was frustrating. It was easy to find the ”}” and delete it,
but I couldn't find a way to place the cursor there! That's funny,
because that should be one of the more basic things to do. Well, I
don't say it's imposible, just that I was stupid enough to not find
the answer. Sorry…

Kind regards

Johnny Rosenberg
ジョニー・ローゼンバーグ

Tom:

Thanks for the response.

Don't overthink this.  I'm not trying to convert anything from WordPerfect.
Rather, I'm trying to just write one for use in Libreoffice (or purloin one
someone else has written).

The Libreoffice documents will have the } character.  I want a macro to find
that character, delete it, and leave the cursor at that position.  It needs
to be one I can assign to a key.

You can assign any macro to a key.

Kind regards

Johnny Rosenberg
ジョニー・ローゼンバーグ

What about this?
<Ctrl>-F
Type '}' and <Enter>
<Esc>
<Del>

Explanation:
Open search box at the bottom for '}' character and search it.
Press <Esc> to hide search box, delete '}' character.
Cursor naturally sits where '}' character was.
Don't need fancy macro for that unless you want to repeat this process many times continuosly, but this is not the case.

cK

Unsubscribe me please!

Am 19.01.2012 17:03, Tom Davies wrote:

Hi :slight_smile:
I found this link
http://www.gmccomb.com/vbafaq.html

... but you did not read.

http://www.gmccomb.com/vbafaq.html wrote:

Will a VBA macro in Microsoft Word run under WordPerfect?

No. Although both may use the VBA language, the two programs use different object models. The difference in object models will preclude a macro written for one program from running on another.

So this is a similar issue as with VBA and StarBasic. The latter is a drunken cousin of the same language familiy, but the thing you are going to talk to a totally different thing and you have to tell different statements in the same language.

Calvin:

I've done it like that. I have a problem if there are no more } characters
in the document. It deletes the next character whatever it is. I'm looking
for something that would notify me if the search finds nothing or would ask
to resume the search at the top.

In WordPerfect I could simply replace the } with nothing rather than using
deleting the text. I haven't been able to effectively do that in
LibreOffice.

Paul

I want to migrate my law office from WordPerfect to Libreoffice.  My
forms
have the } character that I use where I want to input text.  I created a
macro in WordPerfect that searches for that character, deletes it, and
leaves the cursor at the position.  I've assigned the macro to a key so I
can quickly go through documents.

I'm having difficulty learning how to duplicate this in Libreoffice.
Likewise, I'm having difficulty finding one that already does this.

Help please.  Thanks.

Paul

Well, that was frustrating. It was easy to find the ”}” and delete it,
but I couldn't find a way to place the cursor there! That's funny,
because that should be one of the more basic things to do. Well, I
don't say it's imposible, just that I was stupid enough to not find
the answer. Sorry…

Kind regards

Johnny Rosenberg
ジョニー・ローゼンバーグ

What about this?
<Ctrl>-F
Type '}' and <Enter>
<Esc>
<Del>

Explanation:
Open search box at the bottom for '}' character and search it.
Press <Esc> to hide search box, delete '}' character.
Cursor naturally sits where '}' character was.
Don't need fancy macro for that unless you want to repeat this process many
times continuosly, but this is not the case.

Actually I seriously thought it was.

Kind regards

Johnny Rosenberg
ジョニー・ローゼンバーグ

And I'm trying to figure out how to use the world's best word processor--WordPerfect--in Wine.
I really don't know why you would trade all that capability for LO.

--doug

Doug:

My ultimate goal is to migrate from Windows to Linux. Before I do that I
need to assure myself that software running under Linux can do what I've
been doing in the past with various Windows programs.

I'm very comfortable with WordPerfect having used it for almost 25 years.
Nevertheless, like much software I only use a small fraction of its
capabilities. From what I can see LibreOffice is more than capable of
matching everything WordPerfect does. I expect I won't use nearly all of
its capabilities.

The real challenge is making myself learn how to use it. I have a lot of
forms in WordPerfect that were tedious to create, such as bankruptcy and
child support pleadings. I'm not crazy about redoing those in LibreOffice.
Yet, if I get them like I want them I'll have mastered enough of the program
that I can make a smooth migration.

Change is inevitable.

Paul

Do you have the Writer Guide for LibreOffice? You can find it here:
http://wiki.services.openoffice.org/wiki/Documentation/OOo3_User_Guides/Chapters/
     On this same web page is a chapter on macros: Getting Started with
macros (ch 13 in the Getting Started Guide. This might help some, but it
might not.

--Dan

Perhaps you meant:
http://www.libreoffice.org/get-help/documentation/
??

The link you provided is for OOo + it's
"There is currently no text in this page. You can search for this page
title in other pages, search the related logs, or edit this page. "

Hi :slight_smile:
Yes, i think some of the docs team are currently working on both projects at the same time or at least working alongside each other a bit.  The wiki for LO is
http://wiki.documentfoundation.org/Documentation/Publications
but the official page usually gets updated soon after the wiki. 
http://www.libreoffice.org/get-help/documentation/

Even tho the 2 projects have already diverged it is good to see that they can work together in some things imo :slight_smile:
Regards from
Tom :slight_smile:

If I were not lacking in time I would provide a better macro than this, but...... Does this work for you?

sub findAndRemoveChar
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(18) as new com.sun.star.beans.PropertyValue
args1(0).Name = "SearchItem.StyleFamily"
args1(0).Value = 2
args1(1).Name = "SearchItem.CellType"
args1(1).Value = 0
args1(2).Name = "SearchItem.RowDirection"
args1(2).Value = true
args1(3).Name = "SearchItem.AllTables"
args1(3).Value = false
args1(4).Name = "SearchItem.Backward"
args1(4).Value = false
args1(5).Name = "SearchItem.Pattern"
args1(5).Value = false
args1(6).Name = "SearchItem.Content"
args1(6).Value = false
args1(7).Name = "SearchItem.AsianOptions"
args1(7).Value = false
args1(8).Name = "SearchItem.AlgorithmType"
args1(8).Value = 1
args1(9).Name = "SearchItem.SearchFlags"
args1(9).Value = 65536
args1(10).Name = "SearchItem.SearchString"
args1(10).Value = "}"
args1(11).Name = "SearchItem.ReplaceString"
args1(11).Value = ""
args1(12).Name = "SearchItem.Locale"
args1(12).Value = 255
args1(13).Name = "SearchItem.ChangedChars"
args1(13).Value = 2
args1(14).Name = "SearchItem.DeletedChars"
args1(14).Value = 2
args1(15).Name = "SearchItem.InsertedChars"
args1(15).Value = 2
args1(16).Name = "SearchItem.TransliterateFlags"
args1(16).Value = 1280
args1(17).Name = "SearchItem.Command"
args1(17).Value = 0
args1(18).Name = "Quiet"
args1(18).Value = true

dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SwBackspace", "", 0, Array())

end sub

Known issues. (1) This will issue the backspace even if nothing is found. Grumble, unacceptable. grumble grumble...

OK, I will write one myself... how about one of these...

Sub findNextAndRemoveChar()
   Dim oFind
   Dim oFound
   Dim oDoc

   oDoc = ThisComponent
   oFind = oDoc.createSearchDescriptor()
   With oFind
    .SearchString = "}"
   End With

   oFound = oDoc.FindNext(oDoc.CurrentController.ViewCursor, oFind)
   If Not IsEmpty(oFound) Then
     oFound.setString("")
     oDoc.CurrentController.select(oFound)
   End If
End Sub

Sub findFirstAndRemoveChar()
   Dim oFind
   Dim oFound
   Dim oDoc

   oDoc = ThisComponent
   oFind = oDoc.createSearchDescriptor()
   With oFind
    .SearchString = "}"
   End With

   oFound = oDoc.FindFirst(oFind)
   If Not IsEmpty(oFound) Then
     oFound.setString("")
     oDoc.CurrentController.select(oFound)
   End If
End Sub

Andrew:

Thank you for your work. I used your last two and both of them worked fine.

The one that searches for the next } is more useful to me. I would like to
figure out how to make it ask to go to the top to continue the search if it
gets to the end of the document, or just stop the macro without opening the
macro editor window.

Paul

G'day Paul,

Doug:

My ultimate goal is to migrate from Windows to Linux. Before I do that I
need to assure myself that software running under Linux can do what I've
been doing in the past with various Windows programs.

That 's haw I started many years ago. It's worth the effort, but is probably getting easier. My big hold-back was InfoSelect, and I'm still trying.

A quick Google of wordperfect linux brought many interesting looking answers. One link had this snippet:
The site to find WordPerfect, and how to get the various versions of it to run on today's Linuxes, is Rick Moen's_WordPerfect on Linux FAQ_ <http://linuxmafia.com/wpfaq>.

Have you joined a linux user group yet? Most are mail oriented like LO

In a worst case scenario there is virtualisation. Or, depending on how big your practice is, keep 1 windows box on you LAN, for that remainder program. People who need it log in remotely.

I'm very comfortable with WordPerfect having used it for almost 25 years.
Nevertheless, like much software I only use a small fraction of its
capabilities. From what I can see LibreOffice is more than capable of
matching everything WordPerfect does. I expect I won't use nearly all of
its capabilities.

Like most of us.

The real challenge is making myself learn how to use it. I have a lot of
forms in WordPerfect that were tedious to create, such as bankruptcy and
child support pleadings. I'm not crazy about redoing those in LibreOffice.
Yet, if I get them like I want them I'll have mastered enough of the program
that I can make a smooth migration.

Won't they copy/paste while you are still using windows

Change is inevitable.

Paul

--
View this message in context: http://nabble.documentfoundation.org/Need-simple-find-replace-macro-tp3672651p3673689.html
Sent from the Users mailing list archive at Nabble.com.

Keith Bainbridge
PO Box 324
BELMONT Vic 3216 Australia
  +61 (0)408 522 706

keith@akrb.name

So, do these do as you desire? Call findNext.... Notice the difference.

Sub findNextAndRemoveChar()
   Dim oFind
   Dim oFound
   Dim oDoc

   oDoc = ThisComponent
   oFind = oDoc.createSearchDescriptor()
   With oFind
    .SearchString = "}"
   End With

   oFound = oDoc.FindNext(oDoc.CurrentController.ViewCursor, oFind)
   'Inspect oFound
   If Not IsEmpty(oFound) AND NOT IsNull(oFound) Then
     oFound.setString("")
     oDoc.CurrentController.select(oFound)
   ElseIf MsgBox("Not found, continue from top?", 4) = 6 Then
     findFirstAndRemoveChar()
   End If
End Sub

Sub findFirstAndRemoveChar()
   Dim oFind
   Dim oFound
   Dim oDoc

   oDoc = ThisComponent
   oFind = oDoc.createSearchDescriptor()
   With oFind
    .SearchString = "}"
   End With

   oFound = oDoc.FindFirst(oFind)
   If Not IsEmpty(oFound) AND NOT IsNull(oFound) Then
     oFound.setString("")
     oDoc.CurrentController.select(oFound)
   End If
End Sub

Andrew:

The first one seems to work perfect. I didn't try the second one.

Thanks for everything. I spent many weeks racking my brain over this.

Paul