Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. Sub Main
  2.  
  3. On Error Goto ErrorHandler ' Enables error handling
  4.  
  5. Dim oActiveCell
  6. Dim oConv
  7. Dim replace As Object
  8.  
  9.  
  10. oActiveCell = ThisComponent.getCurrentSelection()
  11.  
  12. oConv = ThisComponent.createInstance("com.sun.star.table.CellRangeAddressConversion")
  13.  
  14. oConv.Address = oActiveCell.getRangeAddress
  15.  
  16. Dim oSheet As Object : oSheet = ThisComponent.CurrentController.ActiveSheet
  17.  
  18. replace = oSheet.createReplaceDescriptor
  19. replace.SearchRegularExpression = True
  20. replace.SearchString = "^."
  21. replace.ReplaceString = "&"
  22.  
  23. Dim oRange As Object : oRange = oSheet.getCellRangebyName(oConv.UserInterfaceRepresentation)
  24.  
  25. Dim oCell As Object
  26.  
  27. Dim i As Integer, j As Integer
  28.  
  29. For i = 0 To oRange.Rows.getCount() - 1
  30.  
  31. For j = 0 To oRange.Columns.getCount() - 1
  32.  
  33. oCell = oRange.getCellByPosition( j, i )
  34.  
  35. oCell.replaceAll(replace)
  36.  
  37. Next j
  38.  
  39. Next i
  40.  
  41. msgbox "Concluido"
  42.  
  43. Exit Sub
  44.  
  45. ErrorHandler:
  46.  
  47. If Err = 423 then
  48.  
  49. MsgBox "Essa Macro não funciona com seleções não adjacentes"
  50.  
  51. Else
  52.  
  53. MsgBox "Error code: " + Err + Chr$(13) + Error$
  54.  
  55. End if
  56.  
  57. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement