OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Carriage Returns

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Nalum
Newbie
Newbie


Joined: 04 Oct 2006
Posts: 3

PostPosted: Wed Oct 04, 2006 1:26 am    Post subject: Carriage Returns Reply with quote

Hello, I was wondering if there is a way to search the Document for carriage returns and change them to a word i.e.

"This is a Carriage
Return"

Would instead be:

"This is a Carriage &return; Return"

Thanks for all your help.

Nalum

P.S. I would need it to work with spreadsheets.
Back to top
View user's profile Send private message
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Mon Oct 09, 2006 9:59 am    Post subject: Reply with quote

try this ...
Code:

Sub Main
oSheet = ThisComponent.sheets.getByIndex(0)

oCursor = oSheet.createCursorByRange(oSheet.getCellbyPosition( 0, 0 ))
oCursor.GotoEndOfUsedArea(True)
lCol = oCursor.getRangeAddress().EndColumn
lRow = oCursor.getRangeAddress().EndRow

for kCol=0 to lCol
  for kRow = 0 to lRow
    oCell = oSheet.getCellByPosition(kCol, kRow)
    s = oCell.String
    if s <>"" then
      kCR = InStr(s, Chr(10))
      if kCR>0 then oCell.String = Left(s,kCR-1) & "&Return" & right(s, len(s)-kCR)       
      endif
    next kRow
  next kCol
End Sub
Back to top
View user's profile Send private message
Nalum
Newbie
Newbie


Joined: 04 Oct 2006
Posts: 3

PostPosted: Tue Oct 10, 2006 1:12 am    Post subject: Reply with quote

Thank you very much ms777.

Is there a way that I can get this to check more than once in each cell. At the moment it's only replacing one carrage return?
Back to top
View user's profile Send private message
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Tue Oct 10, 2006 6:42 am    Post subject: Reply with quote

Yes. But this is easy ... good training in OO Basic for you Smile
Back to top
View user's profile Send private message
Nalum
Newbie
Newbie


Joined: 04 Oct 2006
Posts: 3

PostPosted: Tue Oct 10, 2006 6:43 am    Post subject: Reply with quote

Ok thanks again ms777 Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group