Page 1 of 1

[Solved] Open a dialog to a specific tab (and nothing more)

PostPosted: Fri Nov 06, 2020 12:22 am
by cookieJones
I want a command (menu item or toolbar button) to simply open the 'Format Cells' dialog to the 'Numbers' tab, and nothing more.
I usually record my macros, but when I record this one nothing gets saved.
Can someone tell me the secret to doing this? Do I even need a macro?

Re: Open a dialog to a specific tab (and nothing more)

PostPosted: Fri Nov 06, 2020 6:35 pm
by UnklDonald418
The Format Cells dialog saves the tab that was active when the dialog is closed. If you select the Numbers tab before closing the dialog, the next time it will open on the Numbers tab.

Re: Open a dialog to a specific tab (and nothing more)

PostPosted: Fri Nov 06, 2020 8:45 pm
by cookieJones
thanks for the reply but I'm looking for a command, i.e., a way to do it via a macro that can be assigned to a menu item or toolbar button.

Re: Open a dialog to a specific tab (and nothing more)

PostPosted: Fri Nov 06, 2020 9:28 pm
by JeJe
Look at Useful Macro Information For OpenOffice By Andrew Pitonyak (free online)
Section 9.7.2. Discovering the accessible content
If you're able to follow it you may be able to write a similar macro for the dialog you want.

Re: Open a dialog to a specific tab (and nothing more)

PostPosted: Fri Nov 06, 2020 10:19 pm
by UnklDonald418
The macro recorder only records keystrokes (not mouse button clicks or movements) so I recorded a macro using the Format Cells shortcut key Ctrl+1 and got the following code

Code: Select all   Expand viewCollapse view
REM  *****  BASIC  *****


sub Main
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:FormatCellDialog", "", 0, Array())


end sub

Re: Open a dialog to a specific tab (and nothing more)

PostPosted: Sat Nov 07, 2020 1:40 am
by JeJe
This is Listing 9.10 from above modified. Run the FormatCellDialog sub.

Code: Select all   Expand viewCollapse view


Sub FormatCellDialog()
Dim oFrame ' Frame from the current window.
Dim oToolkit ' Container window's com.sun.star.awt.Toolkit
Dim oDisp ' Dispatch helper.
Dim oList ' XTopWindowListener that handles the interactions.
Dim s$
REM Get the com.sun.star.awt.Toolkit
oFrame = ThisComponent.getCurrentController().getFrame()
oToolkit = oFrame.getContainerWindow().getToolkit()
s$ = "com.sun.star.awt.XTopWindowListener"
oList = createUnoListener("TopWFormula_", s$)
oDisp = createUnoService("com.sun.star.frame.DispatchHelper")
REM Insert an OLE object!
oToolkit.addTopWindowListener(oList)
oDisp.executeDispatch(oFrame, ".uno:FormatCellDialog", "", 0, Array())
oToolkit.removeTopWindowListener(oList)
End Sub
Sub TopWFormula_windowOpened(e As Object)

'Dim oAC
'Dim oACRadioButtonNew
'Dim oACList
'Dim oACButtonOK
'REM Get the accessible window, which is the entire dialog.
'oAC = e.source.AccessibleContext
'REM Get the buttons
'oACRadioButtonNew = oAC.getAccessibleChild(0).AccessibleContext
'DIM oAC2
'oAC2 = oAC.getAccessibleChild(2)
'oACList = oAC2.AccessibleContext.getAccessibleChild(0)
'oACButtonOK = oAC.getAccessibleChild(4).AccessibleContext
'REM Select "Create New"
'oACRadioButtonNew.doAccessibleAction(0)
'REM Access the Fifth item in the list (as in 0, 1, 2, 3, 4...)
'oACList.selectAccessibleChild(4)
'214
'REM The accessible action of a command button is to "use" it.
'oACButtonOK.doAccessibleAction(0)
End Sub
Sub TopWFormula_windowClosing(e As Object)
End Sub
Sub TopWFormula_windowClosed(e As Object)
End Sub
Sub TopWFormula_windowMinimized(e As Object)
End Sub
Sub TopWFormula_windowNormalized(e As Object)
End Sub
Sub TopWFormula_windowActivated(e As Object)

static boo as boolean
if boo = false then

boo = true
e.source.accessiblecontext.getaccessiblechild(0).getaccessiblecontext.selectaccessiblechild(0)
end if


End Sub
Sub TopWFormula_windowDeactivated(e As Object)
End Sub

Re: Open a dialog to a specific tab (and nothing more)

PostPosted: Sat Nov 07, 2020 4:03 am
by cookieJones
Thank you JeJe, that looks promising, I'll give it a try and post back.

p.s. took me a while to find that book online but looks really interesting tho will take time to get thru.
Not sure I found the same version you have - in this one that section is 10.7.2)

Re: Open a dialog to a specific tab (and nothing more)

PostPosted: Sat Nov 07, 2020 4:07 am
by cookieJones
UnklDonald418 wrote:The macro recorder only records keystrokes (not mouse button clicks or movements) so I recorded a macro using the Format Cells shortcut key Ctrl+1 and got the following code
end sub[/code]


Thank you UnklDonald418 much appreciated, will take a look at that.

Re: Open a dialog to a specific tab (and nothing more)

PostPosted: Mon Nov 09, 2020 2:38 am
by cookieJones
JeJe wrote:This is Listing 9.10 from above modified. Run the FormatCellDialog sub.

Code: Select all   Expand viewCollapse view


Sub FormatCellDialog()
Dim oFrame ' Frame from the current window.
Dim oToolkit ' Container window's com.sun.star.awt.Toolkit
Dim oDisp ' Dispatch helper.
Dim oList ' XTopWindowListener that handles the interactions.
Dim s$
REM Get the com.sun.star.awt.Toolkit
oFrame = ThisComponent.getCurrentController().getFrame()
oToolkit = oFrame.getContainerWindow().getToolkit()
s$ = "com.sun.star.awt.XTopWindowListener"
oList = createUnoListener("TopWFormula_", s$)
oDisp = createUnoService("com.sun.star.frame.DispatchHelper")
REM Insert an OLE object!
oToolkit.addTopWindowListener(oList)
oDisp.executeDispatch(oFrame, ".uno:FormatCellDialog", "", 0, Array())
oToolkit.removeTopWindowListener(oList)
End Sub
Sub TopWFormula_windowOpened(e As Object)

'Dim oAC
'Dim oACRadioButtonNew
'Dim oACList
'Dim oACButtonOK
'REM Get the accessible window, which is the entire dialog.
'oAC = e.source.AccessibleContext
'REM Get the buttons
'oACRadioButtonNew = oAC.getAccessibleChild(0).AccessibleContext
'DIM oAC2
'oAC2 = oAC.getAccessibleChild(2)
'oACList = oAC2.AccessibleContext.getAccessibleChild(0)
'oACButtonOK = oAC.getAccessibleChild(4).AccessibleContext
'REM Select "Create New"
'oACRadioButtonNew.doAccessibleAction(0)
'REM Access the Fifth item in the list (as in 0, 1, 2, 3, 4...)
'oACList.selectAccessibleChild(4)
'214
'REM The accessible action of a command button is to "use" it.
'oACButtonOK.doAccessibleAction(0)
End Sub
Sub TopWFormula_windowClosing(e As Object)
End Sub
Sub TopWFormula_windowClosed(e As Object)
End Sub
Sub TopWFormula_windowMinimized(e As Object)
End Sub
Sub TopWFormula_windowNormalized(e As Object)
End Sub
Sub TopWFormula_windowActivated(e As Object)

static boo as boolean
if boo = false then

boo = true
e.source.accessiblecontext.getaccessiblechild(0).getaccessiblecontext.selectaccessiblechild(0)
end if


End Sub
Sub TopWFormula_windowDeactivated(e As Object)
End Sub


Thank you JeJe it works! Excellent! Took me a while to set things up, but it works perfectly.

p.s. Which version of 'Useful Macro Information For OpenOffice.org' do you use?
The one I found is Document Revision: 1140 dated June 12, 2015. I was looking in it for something similar to your code, to try to follow it.

Re: Open a dialog to a specific tab (and nothing more)

PostPosted: Mon Nov 09, 2020 2:48 am
by cookieJones
UnklDonald418 wrote:The macro recorder only records keystrokes (not mouse button clicks or movements) so I recorded a macro using the Format Cells shortcut key Ctrl+1 and got the following code

Code: Select all   Expand viewCollapse view
REM  *****  BASIC  *****


sub Main
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:FormatCellDialog", "", 0, Array())


end sub



Thank you UnklDonald418, this almost works except that it opens to the last used tab, not necessarily the numbers tab (as you noted in your first post) but it definitely brings up the correct dialog.

Re: [SOLVED] Open a dialog to a specific tab (and nothing mo

PostPosted: Mon Nov 09, 2020 12:42 pm
by JeJe
My version has Last Modified
Wednesday, January 25, 2006 at 03:48:07 PM

The original listing I modified is:

Code: Select all   Expand viewCollapse view

Listing 9.10: Insert a formula into writer.
Sub InsertFormulaIntoWriter()
Dim oFrame ' Frame from the current window.
Dim oToolkit ' Container window's com.sun.star.awt.Toolkit
Dim oDisp ' Dispatch helper.
Dim oList ' XTopWindowListener that handles the interactions.
Dim s$
REM Get the com.sun.star.awt.Toolkit
oFrame =ThisComponent.getCurrentController().getFrame()
oToolkit = oFrame.getContainerWindow().getToolkit()
s$ = "com.sun.star.awt.XTopWindowListener"
oList = createUnoListener("TopWFormula_", s$)
oDisp = createUnoService("com.sun.star.frame.DispatchHelper")
REM Insert an OLE object!
oToolkit.addTopWindowListener(oList)
oDisp.executeDispatch(oFrame, ".uno:InsertObject", "", 0, Array())
oToolkit.removeTopWindowListener(oList)
End Sub
Sub TopWFormula_windowOpened(e As Object)
Dim oAC
Dim oACRadioButtonNew
Dim oACList
Dim oACButtonOK
REM Get the accessible window, which is the entire dialog.
oAC = e.source.AccessibleContext
REM Get the buttons
oACRadioButtonNew = oAC.getAccessibleChild(0).AccessibleContext
DIM oAC2
oAC2 = oAC.getAccessibleChild(2)
oACList = oAC2.AccessibleContext.getAccessibleChild(0)
oACButtonOK = oAC.getAccessibleChild(4).AccessibleContext
REM Select "Create New"
oACRadioButtonNew.doAccessibleAction(0)
REM Access the Fifth item in the list (as in 0, 1, 2, 3, 4...)
oACList.selectAccessibleChild(4)
214
REM The accessible action of a command button is to "use" it.
oACButtonOK.doAccessibleAction(0)
End Sub
Sub TopWFormula_windowClosing(e As Object)
End Sub
Sub TopWFormula_windowClosed(e As Object)
End Sub
Sub TopWFormula_windowMinimized(e As Object)
End Sub
Sub TopWFormula_windowNormalized(e As Object)
End Sub
Sub TopWFormula_windowActivated(e As Object)
End Sub
Sub TopWFormula_windowDeactivated(e As Object)
End Sub


Re: [Solved] Open a dialog to a specific tab (and nothing mo

PostPosted: Mon Nov 09, 2020 7:44 pm
by cookieJones
Found it - in the version I have, it's Listing 10.2.
I see you did a lot of changes to make it work for my case -
THANK YOU so much. I never would have figured it out.