如何在Libre Office中选择一个又一个电子表格来执行一些操作?
在excel vba中,以下代码有效,但在LibreOffice 中不起作用
Dim wb as Workbook
Dim ws as Worksheet
Set wb = ActiveWorkbook
For Each ws in wb.Worksheets
'Do something here
End if
Next
有人能帮我吗?
首先获取ThisComponent
(Excel中称为ActiveWorkbook
(的oSheets
对象(Excel中也称为Worksheets
(
Sub sheetProcessing()
Dim oSheets As Variant, oSheet As Variant
Dim i As Long
' By Sheet index
oSheets = ThisComponent.getSheets()
For i = 0 To oSheets.getCount() - 1
oSheet = oSheets.getByIndex(i)
Print oSheet.getName() & " - " & oSheet.getCellByPosition(0, 0).getString()
Next i
' Or by Element Names
Dim oElementNames As Variant
oElementNames = oSheets.getElementNames()
For i = LBound(oElementNames) To UBound(oElementNames)
oSheet = oSheets.getByName(oElementNames(i))
Print oSheet.getName() & " - " & oSheet.getCellByPosition(0, 0).getString()
Next i
' Or easiest
For Each oSheet In oSheets
Print oSheet.getName() & " - " & oSheet.getCellByPosition(0, 0).getString()
Next oSheet
End Sub