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

Keyboard macros or custom scripts

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

Postby cookieJones » Fri Nov 06, 2020 12:22 am

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?
Last edited by MrProgrammer on Mon Nov 09, 2020 5:14 pm, edited 3 times in total.
Reason: Add green tick
cookieJones
 
Posts: 22
Joined: Thu Mar 14, 2013 1:05 am

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

Postby UnklDonald418 » Fri Nov 06, 2020 6:35 pm

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.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.8 & LibreOffice 6.4.7.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1396
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Postby cookieJones » Fri Nov 06, 2020 8:45 pm

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.
OpenOffice 4.1.1 on Windows 7 x64
cookieJones
 
Posts: 22
Joined: Thu Mar 14, 2013 1:05 am

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

Postby JeJe » Fri Nov 06, 2020 9:28 pm

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.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1533
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby UnklDonald418 » Fri Nov 06, 2020 10:19 pm

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
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.8 & LibreOffice 6.4.7.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1396
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Postby JeJe » Sat Nov 07, 2020 1:40 am

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
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1533
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby cookieJones » Sat Nov 07, 2020 4:03 am

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)
OpenOffice 4.1.1 on Windows 7 x64
cookieJones
 
Posts: 22
Joined: Thu Mar 14, 2013 1:05 am

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

Postby cookieJones » Sat Nov 07, 2020 4:07 am

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.
OpenOffice 4.1.1 on Windows 7 x64
cookieJones
 
Posts: 22
Joined: Thu Mar 14, 2013 1:05 am

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

Postby cookieJones » Mon Nov 09, 2020 2:38 am

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.
Last edited by cookieJones on Mon Nov 09, 2020 3:55 am, edited 1 time in total.
OpenOffice 4.1.1 on Windows 7 x64
cookieJones
 
Posts: 22
Joined: Thu Mar 14, 2013 1:05 am

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

Postby cookieJones » Mon Nov 09, 2020 2:48 am

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.
OpenOffice 4.1.1 on Windows 7 x64
cookieJones
 
Posts: 22
Joined: Thu Mar 14, 2013 1:05 am

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

Postby JeJe » Mon Nov 09, 2020 12:42 pm

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

Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1533
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby cookieJones » Mon Nov 09, 2020 7:44 pm

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.
OpenOffice 4.1.1 on Windows 7 x64
cookieJones
 
Posts: 22
Joined: Thu Mar 14, 2013 1:05 am


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 2 guests