LibreOffice Calcでエクセルの
Application.ScreenUpdating = False
のようなコードを実行してもシート移動操作を伴った場合にマクロ実行シート以外のシートが表示されてしまう事があります。
LibreOffice Calcでで画面更新を完全に無効にするには、マクロ動作時に不要なシートを非表示にするしかありません。
下記の2つのSub Procedureを考えました。
Sub ScreenSetFreeze ' 不要シート非表示、画面ロック設定
Sub ScreenUnsetFreeze ' 隠しシート表示、画面ロック解除
Option Explicit REM ***** BASIC ***** Global oDoc As Object Global oController As Object Global oSheets As Object Global ArraySheets() As Variant ' ######################################## Sub SetGlobalVar oDoc = ThisComponent oController = oDoc.getCurrentController() oSheets = oDoc.getSheets() End Sub Sub ScreenSetFreeze ' 不要シート非表示、画面ロック設定 If (isnull(oDoc)) Then Call SetGlobalVar End If Dim SheetsCount As Integer Dim ActiveSheetName As String SheetsCount = oSheets.Count ActiveSheetName = oDoc.getCurrentController().getActiveSheet().Name Dim i As Long Erase ArraySheets() Redim ArraySheets() ' ArraySheets <= マクロ実行前に各シートが表示・非表示を記録 For i=0 to SheetsCount-1 ReDim Preserve ArraySheets ( UBound( ArraySheets ) + 1 ) ArraySheets(UBound( ArraySheets )) = CBool(oSheets.getByIndex(i).isVisible) Next For i=0 to SheetsCount-1 If Not (oSheets.getByIndex(i).Name=ActiveSheetName) Then oSheets.getByIndex(i).isVisible = False End If Next ThisComponent.LockControllers() ThisComponent.addActionLock() End Sub 'ScreenSetFreeze Sub ScreenUnsetFreeze ' 隠されたシートを再表示、画面ロック解除 If (isnull(oDoc)) Then Call SetGlobalVar End If Dim SheetsCount As Integer Dim ActiveSheetName As String SheetsCount = oSheets.Count ActiveSheetName = oDoc.getCurrentController().getActiveSheet().Name Dim i As Long For i=0 to SheetsCount-1 If NOT (oSheets.getByIndex(i).Name=ActiveSheetName) Then If NOT (UBound( ArraySheets ) = -1) Then If CBool(ArraySheets(i)) Then oSheets.getByIndex(i).isVisible = True End If End If End If Next ThisComponent.UnlockControllers() ThisComponent.removeActionLock() End Sub 'ScreenUnsetFreeze Sub Main If (isnull(oDoc)) Then Call SetGlobalVar End If Dim ActiveSheetName As String ActiveSheetName = oDoc.getCurrentController().getActiveSheet().Name Dim SheetsCount As Integer SheetsCount = oSheets.Count Dim oSheetName As String Dim oSheet As Object oSheetName = ActiveSheetName If SheetsCount>1 Then oSheet = oSheets.getByIndex(1) Else oSheet = oSheets.getByName(oSheetName) End If Dim StartTime As Double Dim SecondsElapsed As Double StartTime = Timer Call ScreenSetFreeze ' ## 不要シート非表示、画面ロック設定 Application.ScreenUpdating = False Dim i As Long For i = 0 to 10000 oSheet.getCellByPosition(0,i).Value = i Next Call ScreenUnsetFreeze ' ## 隠されたシートを再表示、画面ロック解除 Application.ScreenUpdating = True SecondsElapsed = Timer - StartTime ' 経過時間(秒)を計測 Msgbox("処理時間: " & SecondsElapsed & "秒") End Sub 'Main