von Dumby » Do, 16.04.2009 18:10
Hallo. Ich möchte das folgende Makro nutzen (Code siehe unten), welches ein extra Button in die Toolbar einfügt. Allerdings tauchen 2 Probleme auf und zwar:
1. Möchte ich gerne, dass dieses Makro beim Start von z.B. Open Office Writer ausgeführt wird. Dies sollte, falls möglich, über ein Code angesteuert werden. Also quasi ein Autostart für das unten stehende Makro. Die Makrozuweisung über Extras --> Anpassen ist mir bekannt, aber dies entspricht dann nicht der gewünschten Lösung.
2. Soll mit Hilfe von diesem Button, welcher erzeugt wird, ein anderes Makro gestartet werden. Evtl hat da jemand die Idee zur Umsetzung.
Hab mich schon durch viele Foren durchgelesen, aber nie das passende, was mir weiterhelfen könnte, gefunden. Da ich auf diesem Gebiet recht wenig Ahnung habe, hoffe ich auf eine recht schnelle und vorallem informative Hilfe eurerseits.
MfG
Code: Alles auswählen
REM *** This example creates a new basic macro toolbar button on
REM *** the Writer standard bar. It doesn't add the button twice.
REM *** It uses the Writer image manager to set an external image
REM *** for the macro toolbar button.
Sub AddButtonToToolbar
Dim sToolbar$ : sToolbar = "private:resource/toolbar/standardbar"
Dim sCmdID$ : sCmdID = "macro:///Standard.Module1.Test()"
Dim sDocType$ : sDocType = "com.sun.star.text.TextDocument"
Dim sSupplier$
Dim oSupplier
Dim oModuleCfgMgr
Dim oImageMgr
Dim oToolbarSettings
Dim bHasButton As Boolean
Dim nCount As Integer
Dim oToolbarButton()
Dim nToolbarButtonCount As Integer
Dim i%, j%
REM Retrieve the module configuration manager from the
REM central module configuration manager supplier
sSupplier = "com.sun.star.ui.ModuleUIConfigurationManagerSupplier"
oSupplier = CreateUnoService(sSupplier)
REM Retrieve the module configuration manager with module identifier
REM *** See com.sun.star.frame.ModuleManager for more information
oModuleCfgMgr = oSupplier.getUIConfigurationManager( sDocType )
oImageMgr = oModuleCfgMgr.getImageManager()
oToolbarSettings = oModuleCfgMgr.getSettings( sToolbar, True )
REM Look for our button with the CommandURL property.
bHasButton = False
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
bHasButton = True
End If
End If
Next
Next
Dim oImageCmds(0)
Dim oImages(0)
Dim oImage
REM *** Check if image has already been added
If Not oImageMgr.hasImage( 0, sCmdID ) Then
REM Try to load the image from the file URL
oImage = GetImageFromURL( "file:///tmp/test.bmp" )
If Not isNull( oImage ) Then
REM *** Insert new image into the Writer image manager
oImageCmds(0) = sCmdID
oImages(0) = oImage
oImageMgr.insertImages( 0, oImageCmds(), oImages() )
End If
End If
If Not bHasButton Then
sString = "My Macro's"
oToolbarItem = CreateToolbarItem( sCmdID, "Standard.Module1.Test" )
oToolbarSettings.insertByIndex( nCount, oToolbarItem )
oModuleCfgMgr.replaceSettings( sToolbar, oToolbarSettings )
End If
End Sub
Function GetImageFromURL( URL as String ) as Variant
Dim oMediaProperties(0) As New com.sun.star.beans.PropertyValue
Dim sProvider$ : sProvider = "com.sun.star.graphic.GraphicProvider"
Dim oGraphicProvider
REM Create graphic provider instance to load images from files.
oGraphicProvider = createUnoService( sProvider )
REM Set URL property so graphic provider is able to load the image
REM oMediaProperties(0).Name = "URL"
oMediaProperties(0).Value = URL
REM Retrieve the com.sun.star.graphic.XGraphic instance
GetImageFromURL = oGraphicProvider.queryGraphic( oMediaProperties() )
End Function
Function CreateToolbarItem( Command$, Label$ ) as Variant
Dim aToolbarItem(3) as new com.sun.star.beans.PropertyValue
aToolbarItem(0).Name = "CommandURL"
aToolbarItem(0).Value = Command
aToolbarItem(1).Name = "Label"
aToolbarItem(1).Value = Label
aToolbarItem(2).Name = "Type"
aToolbarItem(2).Value = 0
aToolbarItem(3).Name = "Visible"
aToolbarItem(3).Value = true
CreateToolbarItem = aToolbarItem()
End Function
Hallo. Ich möchte das folgende Makro nutzen (Code siehe unten), welches ein extra Button in die Toolbar einfügt. Allerdings tauchen 2 Probleme auf und zwar:
1. Möchte ich gerne, dass dieses Makro beim Start von z.B. Open Office Writer ausgeführt wird. Dies sollte, falls möglich, über ein Code angesteuert werden. Also quasi ein Autostart für das unten stehende Makro. Die Makrozuweisung über Extras --> Anpassen ist mir bekannt, aber dies entspricht dann nicht der gewünschten Lösung.
2. Soll mit Hilfe von diesem Button, welcher erzeugt wird, ein anderes Makro gestartet werden. Evtl hat da jemand die Idee zur Umsetzung.
Hab mich schon durch viele Foren durchgelesen, aber nie das passende, was mir weiterhelfen könnte, gefunden. Da ich auf diesem Gebiet recht wenig Ahnung habe, hoffe ich auf eine recht schnelle und vorallem informative Hilfe eurerseits.
MfG
[code]REM *** This example creates a new basic macro toolbar button on
REM *** the Writer standard bar. It doesn't add the button twice.
REM *** It uses the Writer image manager to set an external image
REM *** for the macro toolbar button.
Sub AddButtonToToolbar
Dim sToolbar$ : sToolbar = "private:resource/toolbar/standardbar"
Dim sCmdID$ : sCmdID = "macro:///Standard.Module1.Test()"
Dim sDocType$ : sDocType = "com.sun.star.text.TextDocument"
Dim sSupplier$
Dim oSupplier
Dim oModuleCfgMgr
Dim oImageMgr
Dim oToolbarSettings
Dim bHasButton As Boolean
Dim nCount As Integer
Dim oToolbarButton()
Dim nToolbarButtonCount As Integer
Dim i%, j%
REM Retrieve the module configuration manager from the
REM central module configuration manager supplier
sSupplier = "com.sun.star.ui.ModuleUIConfigurationManagerSupplier"
oSupplier = CreateUnoService(sSupplier)
REM Retrieve the module configuration manager with module identifier
REM *** See com.sun.star.frame.ModuleManager for more information
oModuleCfgMgr = oSupplier.getUIConfigurationManager( sDocType )
oImageMgr = oModuleCfgMgr.getImageManager()
oToolbarSettings = oModuleCfgMgr.getSettings( sToolbar, True )
REM Look for our button with the CommandURL property.
bHasButton = False
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
bHasButton = True
End If
End If
Next
Next
Dim oImageCmds(0)
Dim oImages(0)
Dim oImage
REM *** Check if image has already been added
If Not oImageMgr.hasImage( 0, sCmdID ) Then
REM Try to load the image from the file URL
oImage = GetImageFromURL( "file:///tmp/test.bmp" )
If Not isNull( oImage ) Then
REM *** Insert new image into the Writer image manager
oImageCmds(0) = sCmdID
oImages(0) = oImage
oImageMgr.insertImages( 0, oImageCmds(), oImages() )
End If
End If
If Not bHasButton Then
sString = "My Macro's"
oToolbarItem = CreateToolbarItem( sCmdID, "Standard.Module1.Test" )
oToolbarSettings.insertByIndex( nCount, oToolbarItem )
oModuleCfgMgr.replaceSettings( sToolbar, oToolbarSettings )
End If
End Sub
Function GetImageFromURL( URL as String ) as Variant
Dim oMediaProperties(0) As New com.sun.star.beans.PropertyValue
Dim sProvider$ : sProvider = "com.sun.star.graphic.GraphicProvider"
Dim oGraphicProvider
REM Create graphic provider instance to load images from files.
oGraphicProvider = createUnoService( sProvider )
REM Set URL property so graphic provider is able to load the image
REM oMediaProperties(0).Name = "URL"
oMediaProperties(0).Value = URL
REM Retrieve the com.sun.star.graphic.XGraphic instance
GetImageFromURL = oGraphicProvider.queryGraphic( oMediaProperties() )
End Function
Function CreateToolbarItem( Command$, Label$ ) as Variant
Dim aToolbarItem(3) as new com.sun.star.beans.PropertyValue
aToolbarItem(0).Name = "CommandURL"
aToolbarItem(0).Value = Command
aToolbarItem(1).Name = "Label"
aToolbarItem(1).Value = Label
aToolbarItem(2).Name = "Type"
aToolbarItem(2).Value = 0
aToolbarItem(3).Name = "Visible"
aToolbarItem(3).Value = true
CreateToolbarItem = aToolbarItem()
End Function[/code]