5 messages in org.openoffice.fr.progAffecter une macro a un bouton dans u...
FromSent OnAttachments
Didier RetterOct 17, 2006 1:13 pm 
Bernard MarcellyOct 18, 2006 1:34 am 
Didier RetterOct 18, 2006 4:30 am 
Bernard MarcellyOct 18, 2006 5:10 am 
Didier RetterOct 18, 2006 7:49 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Affecter une macro a un bouton dans une autre macroActions...
From:Didier Retter (Didi@ac-nancy-metz.fr)
Date:Oct 17, 2006 1:13:23 pm
List:org.openoffice.fr.prog

Bonjour à tous,

Jusqu'à présent je me suis débrouillé seul (en lisant assiduement ce forum :-) et le bouquin de Laurent et Bernard 8-) ) mais maintenant je cale.

J'ai créé dans une feuille calc, une macro qui charge une autre feuille et qui en autre chose y créer un bouton ce bouton devant appeler une macro

Voici le code seule une infime partie est de moi, la majeure partie vient du net et je l'ai adapté à ma sauce ;-)

Option Explicit

Sub OuvreFiche Dim FicheStock, FicheArticle As Object Dim adresseDoc, leDoc As String Dim FicheArt() Dim maFeuille As Object Dim sel As Object, coord As Object, NewCell As Object Dim oCell As Object, oLigne As Object Dim Col AS Integer Dim Valeur, tArray As Variant ' Teste système d'expoitation utilisé TestSys(leDoc) ' Affectation feuile de stock FicheStock = thisComponent maFeuille = FicheStock.Sheets.getByName ("Stock" ) ' Sélection de l'article sel = FicheStock.currentSelection 'Xray sel if sel.supportsService("com.sun.star.table.Cell") then ' une seule cellule coord = sel.CellAddress 'MsgBox "Une cellule = " & adresseString(FicheStock, coord) ' Test si on ne pointe la bonne colonne et si la cellule n'est pas vide Valeur = sel.getString() if (coord.Column <> 1) or (Valeur = "") Then MsgBox " Vous ne pointez pas sur un article " + chr(13) + chr(13) +_ " Veuillez recommencer " + chr(13) + " " Exit Sub End If ' Recherche de l'index de l'article NewCell = maFeuille.getCellByPosition (coord.Column-1, coord.Row) Valeur = Format(NewCell.getValue, "000") ' Constitution du chemin pour la fiche article à ouvrir leDoc = leDoc & Valeur & ".ods" 'Xray NewCell 'Xray Valeur else MsgBox("Erreur logicielle !", 16) Exit Sub end if ' Conversion chemin => URL adresseDoc = convertToURL(leDoc) ' Ouverture de la fiche Article FicheArticle = StarDesktop.LoadComponentFromURL(adresseDoc, "_blank", 0, FicheArt) 'Insertion d'une ligne maFeuille = FicheArticle.Sheets.getByName ("Feuil1" ) oCell = maFeuille.getCellByPosition(0,2) oLigne = oCell.Rows oLigne.InsertByIndex(0,1) ' Effacement mise en forme tArray=Array(0, 0, 0, 0) for Col = 0 to 6 oCell = maFeuille.getCellByPosition(Col,2) oCell.CellBackColor = RGB(255,255,255) oCell.setPropertyValue("BottomBorder",tArray) oCell.setPropertyValue("LeftBorder",tArray) oCell.setPropertyValue("RightBorder",tArray) next ' Insertion de la date maFeuille.getcellRangebyName("A3").Formula = "=TODAY()" formsincalc(FicheArticle)

End Sub

Sub TestSys(CheminFichier as String) Dim MaVariable As Variant MaVariable = GetGuiType() Select Case MaVariable Case = 1 CheminFichier = "G:\OoCalc\Gestion\StockAtel\FichArt" Case = 4 CheminFichier = "/mnt/usb/OoCalc/Gestion/StockAtel/FichArt" Case Else MsgBox "Ca c'est pas bon !" End Select End Sub

Sub formsincalc(odoc as object) Dim monForm as object Dim osheet as object Dim odrawpage as object Dim button_shape as object Dim button_model as object Dim aPos as new com.sun.star.awt.Point Dim aSize as new com.sun.star.awt.Size dim unEvent as new com.sun.star.script.ScriptEventDescriptor

'odoc = thisComponent

'Recherche l'aire graphique de la feuille nommée "Feuil1" et insère le bouton osheet = odoc.Sheets.getByName("Feuil1") odrawpage = osheet.getDrawPage()

'now create a Shape that will visualize the Buttonmodel button_shape = odoc.createInstance("com.sun.star.drawing.ControlShape")

'Position en 1/1000 de pouce => 1 pouce = 2540 aPos.X = 17500 aPos.Y = 70 button_shape.Position = aPos

'Taille aSize.Width = 3000 aSize.Height = 800 button_shape.Size = aSize

'now create a simple button for it.. button_model = odoc.createInstance("com.sun.star.form.component.CommandButton") button_model.Name = "CmdButton" button_model.Label = "MàJ Stock" button_model.HelpText = "Mise à jour de la valeur du stock dans la fiche principale"

'now connect model and shape with each other button_shape.Control = button_model

'now add it to the drawpage so that it becomes visible.. odrawpage.add(button_shape)

unEvent.ListenerType = "com.sun.star.awt.XMouseListener" unEvent.EventMethod = "mouseReleased" unEvent.ScriptType = "StarBasic" unEvent.ScriptCode = "application:Standard.Essai.Test" 'unEvent.ScriptCode = "StockAtel.ods:Standard.OuvreFiche.Test"

monForm = odrawpage.Forms.getByName( "Standard") monForm.registerScriptEvent(monForm.Count - 1, unEvent)

DesignModeOff(odoc)

End Sub

Sub DesignModeOff(odoc as object)

Dim document, dispatcher as object dim args(0) as new com.sun.star.beans.PropertyValue

document = odoc.CurrentController.Frame dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") args(0).Name = "SwitchControlDesignMode" args(0).Value = false dispatcher.executeDispatch(document, ".uno:SwitchControlDesignMode", "", 0, args())

End Sub

mon pb est ici : ça marche avec la macro Test du module essai de la bibliothèque [Mes Macros et ...] unEvent.ScriptCode = "application:Standard.Essai.Test" avec unEvent.ScriptCode = "document:Standard.Essai.Test" ça ne marche car je pense que OO recherche Test dans la feuille chargée

J'aimerais connaître la structure de la chaîne ScriptCode pour pourvoir définir le chemin de la macro. Des recherches sur http://api.openoffice.org/docs/common/ref/com/sun/star/script/ScriptEventDescriptor.html#ElementDetails n'ont rien donné (ou j'ai rien compris car moi et l'anglais ... :-\ )

J'espère avoir été clair

Merci d'avance

Didier