I'm try to explain my problem, just for check if I'm following the better way to solve it.
My VB .NET procedure opens a document with Writer, but I need to hide some functions such as Print or SaveAs. I'm able to hide some toolbar buttons ceating a new ooBasic macro, but I can't do it from VB .NET; for this reason I need to launch a ooBasic macro from VB .NET
It's the better way or there is another way?
So, I put here a few lines of code.
The following OOBASIC MACRO code is able to hide some tool bar's buttons.
Code: Select all
Sub Main
REM *** Initialize strings
sToolbar = "private:resource/toolbar/standardbar"
sCmdId = ".uno:Save"
REM *** Retrieve the desktop service
oDesktop = createUnoService("com.sun.star.frame.Desktop")
REM *** Retrieve the current frame and layout manager
oCurrFrame = oDesktop.getCurrentFrame()
oLayoutManager = oCurrFrame.LayoutManager
REM *** Try to retrieve the toolbar from the layout manager
oToolbar = oLayoutManager.getElement( sToolbar )
REM *** Retrieve settings from toolbar ***
oToolbarSettings = oToolbar.getSettings( true )
index = -1
nCount = oToolbarSettings.getCount()
for i = 0 to nCount-1
oToolbarButton() = oToolbarSettings.getByIndex( i )
nToolbarButtonCount = ubound(oToolbarButton())
for j = 0 to nToolbarButtonCount
if oToolbarButton(j).Name = "CommandURL" then
if oToolbarButton(j).Value = sCmdId then
index = i
end if
endif
next j
next i
if index <> -1 then
REM *** Retrieve current Persistent state
REM *** from property
bPersistent = oToolbar.Persistent
REM *** To make our changes non-persistent
REM *** we have to set the Persistent property
REM *** to false
oToolbar.Persistent = false
REM *** Retrieve button settings
oButtonSettings = oToolbarSettings.getByIndex( index )
REM *** Change the visibility property of the button
for j = 0 to ubound(oButtonSettings())
if oButtonSettings(j).Name = "IsVisible" then
oButtonSettings(j).Value = FALSE
endif
next j
REM *** Replace button settings
oToolbarSettings.replaceByIndex( index, oButtonSettings )
REM *** Set new settings at our toolbar
oToolbar.setSettings( oToolbarSettings )
REM *** Reset Persistent property to old value
oToolbar.Persistent = bPersistent
end if
End Sub
Now... this VB .NET code is able to open an Open Office document.
Code: Select all
Dim oSM 'Root object for accessing OpenOffice from VB
Dim oDesk, oDoc As Object 'First objects from the API
Dim arg() 'Ignore it for the moment !
Dim OpenPar(1) As Object 'a Visual Basic array, with 3 elements
OpenPar(0) = MakePropertyValue("ReadOnly", False)
OpenPar(1) = MakePropertyValue("Password", "secret")
'Instanciate OOo : this line is mandatory with VB for OOo API
oSM = CreateObject("com.sun.star.ServiceManager")
'Create the first and most important service
oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
'Open an existing doc (pay attention to the syntax for first argument)
oDoc = oDesk.loadComponentFromURL("file:///c:/doc.sxw", "_blank", 0, OpenPar)
How can I merge these two code snippet?
thank u!