| View previous topic :: View next topic |
| Author |
Message |
augux General User

Joined: 31 Jan 2006 Posts: 6 Location: Novo Hamburgo, RS, Brasil
|
Posted: Tue Jan 31, 2006 8:04 am Post subject: AutoCorrect after pasting text. |
|
|
I need a feature (which can be a macro or anything else) that helps me
autocorrecting some text when I past it into an OpenOffice.org Writer
document.
I tried OOo autocorrect function but it does only work when I type a
text, not when I paste text.
Ex.: I have some lines like those:
ALLOWED
NOT ALLOWED
NEEDS AUTHORIZATION
I want OOo to autocorrect them when I past them into a document, so
this text can look like:
USER IS ALLOWED, THE SYSTEM DOESN'T ALLOW THIS PERSON, HE NEEDS
AUTHORIZATION FOR THIS.
The example above is only an example; I will use a different and larger
amount of text and there's no pattern for those "corrections": each
text will be replaced by its own correct form. And the "returns" will
be replaced by ", " (comma and space).
Btw, I CANNOT install any kind of software on these computers we use, but it seems to me I can use macros with no problems.
Version of OOo installed: 1.9.128.
AugustoGabriel. _________________ Augusto Gabriel Feyh |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8984 Location: Lexinton, Kentucky, USA
|
Posted: Tue Jan 31, 2006 12:06 pm Post subject: |
|
|
Here is a macro example of how to do this type of thing. Please note that I have changed the searched for terms so they are unique otherwise you will get unexpected results, e.g., ALLOWED to @ALLOWED . | Code: | Sub ChangeStuff 'Using find & replace.
REM We need to to look for text that will not appear in the document
'after a search and replace has occured so the searched for words
'should be unique. 3 separate searches are preformed below.
REM Populate an array.
CurrentText() = Array("@ALLOWED","@NOT ALLOWED","@NEEDS AUTHORIZATION")
REM Another way to populate an array.
Dim Replace(2)
Replace(0) = "USER IS ALLOWED, "
Replace(1) = "THE SYSTEM DOESN'T ALLOW THIS PERSON,"
Replace(2) = "HE NEEDS AUTHORIZATION FOR THIS."
oDoc = thisComponent
FandR = oDoc.createReplaceDescriptor
For i = lBound(CurrentText()) to uBound(CurrentText())
FandR.setSearchString(CurrentText(i))
FandR.setReplaceString(Replace(i))
oDoc.ReplaceAll(FandR)
Next i
End Sub |
|
|
| Back to top |
|
 |
Bhikkhu Pesala Super User


Joined: 23 Aug 2005 Posts: 2324 Location: Seven Kings, London, UK
|
Posted: Tue Jan 31, 2006 1:47 pm Post subject: |
|
|
Also have a look at Autotext. It might be easier to edit than a macro. Aftter pasting each abbreviation you press F3 to convert it to the long form, e.g. tyvm + F3 = Thank you very much for your letter of _________________ Fonts * Opera * Oo Tips * FAQ * New Forum
Oo 2.3.1 * Win XP |
|
| Back to top |
|
 |
augux General User

Joined: 31 Jan 2006 Posts: 6 Location: Novo Hamburgo, RS, Brasil
|
Posted: Wed Feb 01, 2006 8:46 am Post subject: |
|
|
Bhikkhu Pesala: I haven't tried your idea because it seems to me that it would only works with single words, but the text I paste into writer has spaces between words and even spaces after them... so I user JohnV's code.
JohnV: Your code worked, and I'm editing it so I can use it in my document. Thank you VERY much!
But, I still have two things to resolve:
1) The following line will become VERY large in my code:
| Code: | | CurrentText() = Array("@ALLOWED","@NOT ALLOWED","@NEEDS AUTHORIZATION") |
Is there a way for me to use it in several lines? Using this part of the code in only one line will not be "easy-to-use"...
2) The original text has each item in a different line and there may be some spaces after each word, before the line break. E. g.:
FOOTBALL
SOCCER
VOLLEYBALL
And I want them in the same paragraph:
FOOTBALL, SOCCER, VOLLEYBALL
So, how can I replace "line breaks" to comma and space? _________________ Augusto Gabriel Feyh |
|
| Back to top |
|
 |
augux General User

Joined: 31 Jan 2006 Posts: 6 Location: Novo Hamburgo, RS, Brasil
|
Posted: Wed Feb 01, 2006 9:38 am Post subject: |
|
|
My first doubt of the last post has been solved: I just tried the second way to populate arrays that JohnV has posted! _________________ Augusto Gabriel Feyh |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8984 Location: Lexinton, Kentucky, USA
|
Posted: Wed Feb 01, 2006 1:44 pm Post subject: |
|
|
I thought there was a good reason to show two way to set up an array
If I understand your second question you put the commas and spaces in the replacement text that goes in the Replace array (see my original post) or organize the actual document in a way that includes them as part of its text. As an example of the last of these lets say you have a document where you want two paragraphs as follows:
Not everyone can kick a football.
Not everyone can kick a football, head a soccer ball or spike a volley ball.
Then set it up as:
@F.
@F,<space>@S<space>@V.
Your Replace array would not contain any spacing or punctuation as you have provided it in the document. Note that this allows you to use @F as both a sentence and a phrase.
Hope this makes sense. Put another way, you can have the macro replace your shortcuts with text but you cannot expect it to organize or compose your document. |
|
| Back to top |
|
 |
augux General User

Joined: 31 Jan 2006 Posts: 6 Location: Novo Hamburgo, RS, Brasil
|
Posted: Sun Feb 05, 2006 4:37 pm Post subject: |
|
|
JohnV: in fact, I'll always have a text like this one:
@A
@B
@C
That should be replaced by something like:
Australia, Brazil, Canada,
But I'll always have several lines (avarage: 20), so I'd like this macro to ease my work, by replacing every occurance of a <line break> by <comma><space>.
As I see, OOo replace function doesn't support line breaks (or even tabs, but that's not what I need).
With my current macro, I organize the text right after I run the macro, by deleting those line breaks and writing those commas and spaces. _________________ Augusto Gabriel Feyh |
|
| Back to top |
|
 |
Gabor Super User

Joined: 21 Sep 2003 Posts: 610 Location: Hungary (E-Europe)
|
Posted: Sun Feb 05, 2006 5:14 pm Post subject: Try this |
|
|
| Code: | Function ChangeLinebreakToCommmaSpace
dim odoc, oRD
oDoc=thiscomponent
oRD=oDoc.createReplaceDescriptor
oRD.searchRegularExpression=TRUE
oRD.setSearchString("\n")
oRD.setReplaceString(", ")
Zapall=oDoc.replaceall(oRD)
end function |
Try to include this in your macro, this will change line breaks to commaspaces. If you include it in another macro the
dim odoc, oRD
must be commented out. I am far from being a macro expert, I think I took this one from A. C. Brown's fine macro doc. |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8984 Location: Lexinton, Kentucky, USA
|
Posted: Mon Feb 06, 2006 5:33 am Post subject: |
|
|
To convert a vertical list of short cuts and have it replaced by a paragraph of text separated by <comma> and <space> you do much as Gabor has indicated. In your post you use the term "line break" but you may mean "paragraph break".
Add the following to my macro just above End Sub:
FandR.searchRegularExpression = true
FandR.setSearchString("\n") 'use ("$") for paragraph breaks
FandR.setReplaceString(", ")
oDoc.ReplaceAll(FandR) |
|
| Back to top |
|
 |
augux General User

Joined: 31 Jan 2006 Posts: 6 Location: Novo Hamburgo, RS, Brasil
|
Posted: Tue Feb 07, 2006 7:21 am Post subject: |
|
|
Thanks Gabor and JohnV... my English is not 100% yet, so sometimes I make some mistakes!
I'll try your last codes as soon as possible, then I'll post here if it goes successful! _________________ Augusto Gabriel Feyh |
|
| Back to top |
|
 |
augux General User

Joined: 31 Jan 2006 Posts: 6 Location: Novo Hamburgo, RS, Brasil
|
Posted: Tue Feb 07, 2006 7:30 am Post subject: |
|
|
Well, the code worked very fine.
Now I'm going to test it some more times and send it to other people of my company.
By the way, I work at Banco do Brasil S. A. (Bank of Brazil, Inc): www.bb.com.br
Thanks a lot for you help! _________________ Augusto Gabriel Feyh |
|
| Back to top |
|
 |
|