[TriLUG] openoffice question
Jim Wright
wrightjim at gmail.com
Wed Jan 4 23:38:31 EST 2006
This thread got me thinking about finding out how easy it is to write
a macro in OO...unfortunately I'd say the answer is "not so easy". I
can definitely see the power of OO's object oriented model, but I
think a lot of people who use Excel macros heavily would balk at
it...here is what I came up with for the stated problem...basically it
will fill in below the selected cell with the next IP's in a range,
assuming the selected cell has a valid IP in it....
Sub AutoFillIP()
oSheet = ThisComponent.CurrentController.ActiveSheet
oActiveCell = ThisComponent.GetCurrentSelection
oRange = oActiveCell.RangeAddress
iStartRow = oRange.StartRow + 1
iStartColumn = oRange.StartColumn
' check to make sure the ip is valid
sFirstIP = Split(oActiveCell.String,".")
bValidIP = True
If UBound(sFirstIP) = 3 Then
For i = 0 To 3
If val(sFirstIP(i)) < 0 OR val(sFirstIP(i)) > 254 Then
msgbox(sFirstIP(i))
bValidIP = False
End if
Next
Else
bValidIP = False
End If
If bValidIP = False Then
MsgBox("The selected cell needs to have a valid IP address in it.")
Exit Sub
End If
For i = val(sFirstIP(3)) + 1 To 254
oActiveCell = oSheet.getCellByPosition(iStartColumn,iStartRow)
oActiveCell.String = sFirstIP(0) & "." & sFirstIP(1) & "." &
sFirstIP(2) & "." & i
iStartRow = iStartRow + 1
Next
End Sub
More information about the TriLUG
mailing list