I posted at the end.... Jason Brower wrote:
Most of the following macros came from my free macro document with better coverage in my book. The following macro will deal with selected text and then swap things around. This assumes that you have a new paragarph between each line.Thank you... I am sure there is a way to do that automtically with a macro from those instructions, no?
-------- Jason Brower
On Wed, 2005-04-13 at 16:13 -0400, Anthony Chilco wrote:
Hi Jason,
If the file is plain text, with commas separating the names you could change the extension to 'csv' and import it into calc. When you do that, you'll have an opportunity to parse the file into columns. You'll then be able to sort by first or last name. You can then save the file as csv text again.
tc
Jason Brower wrote:
Is there a way to recognize a flat list of names like Brower, Jason Doe, John Doe, Jane Sucks, Windows Matrix, Enterthe
and have it not only switch the names to first and last but to sort by first of last name without switching.
Trying to do it in MS word, not possible, or couldn't find it.
If it is not in OO can it be?
Same with speach with festival would be nice.
Sub SwapNames Dim oCursors(), i% If Not CreateSelectedTextIterator(ThisComponent, _ "Print characters for the entire document?", oCursors()) Then Exit Sub For i% = LBound(oCursors()) To UBound(oCursors()) SwapNamesWorker(oCursors(i%, 0), oCursors(i%, 1)) Next i% End Sub
'Author: Andrew Pitonyak 'email: [EMAIL PROTECTED] Sub SwapNamesWorker(oLCursor, oRCursor) Dim oText Dim sFirstWord$
If IsNull(oLCursor) Or IsNull(oRCursor) Or IsNull(oText) Then Exit Sub
oText = oLCursor.getText()
If oText.compareRegionEnds(oLCursor, oRCursor) <= 0 Then Exit Sub
If NOT oLCursor.isStartOfParagraph() Then
oLCursor.gotoStartOfParagraph(False)
End If
Do While oLCursor.gotoEndOfWord(True) AND oText.compareRegionEnds(oLCursor, oRCursor) >= 0
sFirstWord = oLCursor.getString()
If NOT oLCursor.gotoNextWord(True) Then Exit Sub
oLCursor.setString("")
If NOT oLCursor.gotoEndOfWord(False) Then
oLCursor.setString(sFirstWord)
Exit Sub
End If
oLCursor.setString(", " & sFirstWord)
If NOT oLCursor.gotoNextParagraph(False) Then Exit Sub
Loop
End SubFunction IsAnythingSelected(oDoc As Object) As Boolean Dim oSelections 'All of the selections Dim oSel 'A single selection Dim oCursor 'A temporary cursor
IsAnythingSelected = False If IsNull(oDoc) Then Exit Function ' The current selection in the current controller. 'If there is no current controller, it returns NULL. oSelections = oDoc.getCurrentSelection() If IsNull(oSelections) Then Exit Function
REM I have never seen a selection count of zero If oSelections.getCount() = 0 Then Exit Function
REM If there are multiple selections, then certainly something is selected If oSelections.getCount() > 1 Then IsAnythingSelected = True Else REM If only one thing is selected, however, then check to see if the REM selection is collapsed. In other words, see if the end location is REM the same as the starting location. REM Notice that I use the text object from the selection object REM because it is safer than assuming that it is the same as the REM documents text object. oSel = oSelections.getByIndex(0) oCursor = oSel.getText().CreateTextCursorByRange(oSel) If Not oCursor.IsCollapsed() Then IsAnythingSelected = True End If End Function
'****************************************************************** 'Author: Andrew Pitonyak 'email: [EMAIL PROTECTED] 'oSelection is a text selection or cursor range 'oText is the text object Function GetLeftMostCursor(oSel As Object, oText As Object) As Object Dim oRange As Object, oCursor As Object
If oText.compareRegionStarts(oSel.getEnd(), oSel) >= 0 Then oRange = oSel.getEnd() Else oRange = oSel.getStart() End If oCursor = oText.CreateTextCursorByRange(oRange) oCursor.goRight(0, False) GetLeftMostCursor = oCursor End Function '****************************************************************** 'Author: Andrew Pitonyak 'email: [EMAIL PROTECTED] 'oSelection is a text selection or cursor range 'oText is the text object Function GetRightMostCursor(oSel As Object, oText As Object) As Object Dim oRange As Object, oCursor As Object
If oText.compareRegionStarts(oSel.getEnd(), oSel) >= 0 Then oRange = oSel.getStart() Else oRange = oSel.getEnd() End If oCursor = oText.CreateTextCursorByRange(oRange) oCursor.goLeft(0, False) GetRightMostCursor = oCursor End Function
'******************************************************************
'Author: Andrew Pitonyak
'email: [EMAIL PROTECTED]
'sPrompt : how to ask if should iterate over the entire text
'oCursors() : Has the return cursors
'Returns true if should iterate and false if should not
Function CreateSelectedTextIterator(oDoc As Object, sPrompt As String, oCursors()) As Boolean
Dim oSelections As Object, oSel As Object, oText As Object
Dim lSelCount As Long, lWhichSelection As Long
Dim oLCursor As Object, oRCursor As Object
CreateSelectedTextIterator = True
oText = oDoc.Text
If Not IsAnythingSelected(ThisComponent) Then
Dim i%
i% = MsgBox("No text selected!" + Chr(13) + sPrompt, _
1 OR 32 OR 256, "Warning")
If i% = 1 Then
oLCursor = oText.createTextCursor()
oLCursor.gotoStart(False)
oRCursor = oText.createTextCursor()
oRCursor.gotoEnd(False)
oCursors = DimArray(0, 1)
oCursors(0, 0) = oLCursor
oCursors(0, 1) = oRCursor
Else
oCursors = DimArray()
CreateSelectedTextIterator = False
End If
Else
oSelections = ThisComponent.getCurrentSelection()
lSelCount = oSelections.getCount()
oCursors = DimArray(lSelCount - 1, 1)
For lWhichSelection = 0 To lSelCount - 1
oSel = oSelections.getByIndex(lWhichSelection)
'If I want to know if NO text is selected, I could
'do the following:
'oLCursor = oText.CreateTextCursorByRange(oSel)
'If oLCursor.isCollapsed() Then ...
oLCursor = GetLeftMostCursor(oSel, oText)
oRCursor = GetRightMostCursor(oSel, oText)
oCursors(lWhichSelection, 0) = oLCursor
oCursors(lWhichSelection, 1) = oRCursor
Next
End If
End Function
-- Andrew Pitonyak My Macro Document: http://www.pitonyak.org/AndrewMacro.sxw My Macro Book: http://www.hentzenwerke.com/catalog/oome.htm Free Info: http://www.pitonyak.org/oo.php
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
