Advertisement
Mark2020H

Using Basic with Libre office Calc

Aug 11th, 2022
3,041
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. REM  *****  BASIC  ***** FOR  Those who are wanting to learn about  Libre Office Calc Macro's  with forms  ****
  2. REM  ****  Video Tutorial On Facebook for those who would like to see intro to this  @
  3. REM  ********        https://www.facebook.com/mark.harrington.142892 *****************
  4.  
  5. sub PopRange
  6. dim cell as object
  7. dim i as variant
  8. dim sheets
  9.  
  10. sheet = thiscomponent.sheets(0)
  11. i = 0.0
  12.  
  13.  
  14. while i < 40.0
  15.    
  16.     cell = Sheet.getCellByPosition(0,i)
  17.     cell.setValue( i )
  18.     i = i+1
  19.     call ExampleWait
  20.    
  21. wend
  22.    
  23.  
  24. End Sub
  25.  
  26.  
  27. REM Function to  give delay
  28.  
  29. Sub ExampleWait
  30.     Dim lTick As Long
  31.         lTick = GetSystemTicks()
  32.         Wait 500
  33.        
  34.        
  35. End Sub
  36.  
  37. REM *******  function to clear cell contents
  38.  
  39. Sub ClearRangeContents
  40.  
  41.  
  42.  
  43.     Dim oFlags As Long
  44.    
  45.  
  46.     oFlags = com.sun.star.sheet.CellFlags.VALUE + _
  47.         com.sun.star.sheet.CellFlags.DATETIME + _
  48.         com.sun.star.sheet.CellFlags.STRING + _
  49.         com.sun.star.sheet.CellFlags.ANNOTATION + _
  50.         com.sun.star.sheet.CellFlags.FORMULA + _
  51.         com.sun.star.sheet.CellFlags.HARDATTR + _
  52.         com.sun.star.sheet.CellFlags.STYLES + _
  53.         com.sun.star.sheet.CellFlags.OBJECTS + _
  54.         com.sun.star.sheet.CellFlags.EDITATTR
  55.        
  56.        
  57.   ThisComponent.Sheets(0).GetCellRangeByName("A1:A40").ClearContents(oFlags)
  58.  
  59.  
  60. End Sub
  61.  
  62. REM ***** Function that checks for odd  numbers and   colors cells background  color
  63.  
  64. Sub Check_ForODD_Numbers
  65. Dim oRange As Object  
  66. Dim oCell As Object
  67.  
  68. Dim oSheet As Object  
  69. ODDcolor = RGB(255,0,0)
  70. EvenColor = RGB(0,0,255)
  71.  
  72.  
  73.  oSheet = ThisComponent.sheets(0)
  74.  oRange = oSheet.getCellRangebyName("A1:A40")
  75.    
  76. Dim i As Integer, j As Integer
  77.     For i = 0 To oRange.Rows.getCount() - 1             REM Traverse all cells in the specified range:
  78.         For j = 0 To oRange.Columns.getCount() - 1
  79.             oCell = oRange.getCellByPosition( j, i )
  80.             mval =oCell.Value 'get the value
  81.             m_odd = mval mod 2
  82.             if m_odd <> 0 then
  83.             oCell.CellBackColor = ODDcolor
  84.             else
  85.             oCell.CellBackColor = EvenColor
  86.             end if
  87.         call ExampleWait   
  88.         next j
  89.      next i
  90.    
  91. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement