Bonjour,

Ton exemple a été un très bon guide.
J'ai donc créé 2 macros distinctes auxquelles j'ai attribué les raccourcis
Ctrl+Alt+A -> Mode_Stage
Ctrl+Alt+S -> Mode_Apprenti.

Sub Mode_Stage
  with ThisComponent

.TextFieldMasters.getByName("com.sun.star.text.fieldmaster.SetExpression.Mode").DependentTextFields(0).content = "Stage"

createUnoService("com.sun.star.frame.DispatchHelper").executeDispatch(.CurrentController.Frame, ".uno:UpdateFields", "", 0, Array())
  end with
End Sub

Sub Mode_Apprenti
  with ThisComponent

.TextFieldMasters.getByName("com.sun.star.text.fieldmaster.SetExpression.Mode").DependentTextFields(0).content = "Apprenti"

createUnoService("com.sun.star.frame.DispatchHelper").executeDispatch(.CurrentController.Frame, ".uno:UpdateFields", "", 0, Array())
  end with
End Sub


Merci :-D


Le 21/09/2021 à 22:49, Patrick a écrit :
Bonsoir Stéphane,

Le 21/09/2021 à 22:28, Stéphane Santon a écrit :
Maintenant, je préfèrerai avoir 2 boutons distincts : "Stage"  et "Apprenti" qui basculeront la variable d'une valeur à l'autre.
Voici la macro que j'utilise pour changer la valeur de la variable, affectée à un bouton dans la barre d'outils : Ma variable s'appelle "Type" et les valeurs "Sujet" ou "Correction" et je bascule entre les deux.


sub ToggleType()
dim nomType as string
dim newType as string
dim elements(20)
dim document   as object
dim dispatcher as object

     document   = ThisComponent.CurrentController.Frame
     dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

     elements = ThisComponent.TextFieldMasters.getElementNames()

     ' Chercher la variable "Type"
     for i=0 to ubound(elements)
         if (instr(elements(i),"Type")>0) then

                 ' Récupérer la valeur du Type
                nomType = ThisComponent.TextFieldMasters.getByName(elements(i)).DependentTextFields(0).content
                 if (nomType = "Correction")then
                     newType = "Sujet"
                 else
                     newType = "Correction"
                 endif

ThisComponent.TextFieldMasters.getByName(elements(i)).DependentTextFields(0).content = newType                 dispatcher.executeDispatch(document, ".uno:UpdateFields", "", 0, Array())

         endif
     next i
End sub





--
Envoyez un mail à [email protected] pour vous désinscrire
Les archives de la liste sont disponibles à 
https://listarchives.libreoffice.org/fr/users/
Privacy Policy: https://www.documentfoundation.org/privacy

Répondre à