And what to add the Progressbar to the main loop in the macro?
Sub ProgressBarExample 'show progressBar in some loop
dim oDoc as object, oSheet as object, bCancel as boolean
oDoc=ThisComponent
oSheet=oDoc.CurrentController.ActiveSheet
oDoc.CurrentController.ComponentWindow.Visible=false 'hide the sheets (no blink during exporting the ranges)
rem progressbar
dim oDlg as object, oPrubeh as object, oButton as object
dim iMin&, iMax& 'minimum and maximum value for the progressbar
iMin=0 : iMax=300
oDlg=progressBarInit(iMin, iMax, oDoc) 'show the progressbar
oDlg.title="I love watching the progressbar :-)"
oPrubeh=oDlg.getControl("Pprogress")
oButton=oDlg.getControl("Pbutton")
dim i&, i2&
const iStep=10
for i=iMin to iMax 'main loop
i2=i2+1
if i2=iStep then 'increase value in the progressbar after some step (faster than one by one)
oPrubeh.value=i
i2=0
end if
if oButton.Model.state=1 then 'test if Cancel was pressed
bCancel=true
exit for
end if
wait 10
next i
oDlg.dispose() 'dispose the progressbar
if bCancel=true then msgbox("Cancel was pressed") 'Cancel button in progreesbar was pressed
oDoc.CurrentController.ComponentWindow.Visible=true 'show the sheets
'oDoc.CurrentController.ActiveSheet=oSheet 'reactivate the active sheet
End Sub
Function progressBarInit(min&, max&, optional oDoc as object) as object 'return the object of the dialog window for the progrees bar with the setted min&max values; if the oDoc is present then it do peer for the dialog window to the oDoc else to the desktop
on local error goto chyba
dim oDlg as object, oDlgModel as object, oButtonModel as object, oProgress as object, oWindow as Object
rem model for the dialog window
oDlgModel=CreateUnoService("com.sun.star.awt.UnoControlDialogModel") 'model dialogového okna
with oDlgModel
.Width=140
.Height=45
.positionX=100 'position X from the left-top corner of the window from the macro start() runs
.positionY=140 'position Y
end with
rem progressbar
oProgress=oDlgModel.createInstance("com.sun.star.awt.UnoControlProgressBarModel") 'objekt ukazatele průběhu
with oProgress
.Name="Pprogress" 'name for the macros
.ProgressValueMin=min 'minimal value
.ProgressValueMax=max 'maximal value
.ProgressValue=0 'current value
.Width=120
.Height=15
.positionX=10 'the position X in the dialog window
.positionY=5 'position Y
.Border=3 'the type of the border
end with
oDlgModel.insertByName("Pprogress", oProgress) 'put into the model
rem button Cancel
oButtonModel=oDlgModel.createInstance("com.sun.star.awt.UnoControlButtonModel") 'object of the button
with oButtonModel
.Name="Pbutton"
.Width=40
.Height=15
.PositionX=50
.PositionY=25
.Label="Cancel"
.PushButtonType=com.sun.star.awt.PushButtonType.STANDARD
.TabIndex=0
.Toggle=true 'activate the detection of the State property
end with
oDlgModel.insertByName("Pbutton", oButtonModel)
rem show the dialog window
oDlg=CreateUnoService("com.sun.star.awt.UnoControlDialog") 'final dialog
oDlg.setModel(oDlgModel) 'set the model to the final dialog
rem add dialog window to the oDoc window or to the Desktop
oWindow=CreateUnoService("com.sun.star.awt.Toolkit") 'dialog window
if isMissing(oDoc) then 'add to the desktop (be carefull because the systme can show the message like: the apllication does't respond)
oDlg.createPeer(oWindow,null)
else 'add to the oDoc window (oDoc is the parent, dialog is the child)
dim oToolkit as object
oToolkit=oDoc.currentController.frame.containerWindow
oDlg.createPeer(oWindow,oToolkit) 'show the dialog
end if
progressBarInit=oDlg
exit function
chyba:
MsgBox "Error " & Err & ": " & Error$ + chr(13) + "Line: " + Erl , 16 ,"progressBarInit"
End Function