123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- REM ***** BASIC *****
- Sub generate_id()
- REM Generate a 16-character long random ID for Pocket Archive.
- REM Use this macro in Libreoffice Calc on a single or multiple cells for
- REM quickly filling in any range of cells with fresh IDs.
- REM The CurrentSelection will even contain the stacked ranges
- REM of additional sheets IF MORE THAN ONE SHEET IS SELECTED.
- Const CHARS As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
- Const STRING_LENGTH As Integer = 16
- Dim oSelection As Object
- Dim oCell As Object
- Dim sRandomString As String
- Dim i As Integer
- Dim iCharIndex As Integer
- Dim iCharsLength As Integer
- ' Get the current selection.
- iCharsLength = Len(CHARS)
- sel =ThisComponent.CurrentSelection
- If sel.supportsService("com.sun.star.sheet.SheetCellRanges") Then
- rgs = sel
- Else
- If NOT sel.supportsService("com.sun.star.sheet.SheetCellRange") Then Exit Sub
- rgs = ThisComponent.createInstance("com.sun.star.sheet.SheetCellRanges")
- rgs.addRangeAddress(sel.RangeAddress, False)
- End If
- For Each rg In rgs
- uR = rg.Rows.Count - 1
- uC = rg.Columns.Count - 1
- Randomize
- For r = 0 To uR
- For c = 0 To uC
- rcCell = rg.getCellByPosition(c, r)
- sRandomString = ""
- For i = 1 To STRING_LENGTH
- iCharIndex = Int((iCharsLength * Rnd) + 1)
- sRandomString = sRandomString & Mid(CHARS, iCharIndex, 1)
- Next i
- rcCell.setString(sRandomString)
- Next c
- Next r
- Next rg
- End Sub
|