IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBA Outlook Discussion :

Cliquer sur un bouton d'un onglet du ruban par VBA [OL-2010]


Sujet :

VBA Outlook

  1. #1
    Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2017
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Service public

    Informations forums :
    Inscription : Octobre 2017
    Messages : 2
    Points : 2
    Points
    2
    Par défaut Cliquer sur un bouton d'un onglet du ruban par VBA
    Bonjour,

    J'ai installé l'application gSyncit pour Outlook pour synchroniser mon Google Agenda et mon calendrier Outlook.

    Cela a eu pour conséquence d'ajouter un onglet "gSyncit" au ruban dans lequel il y a deux groupes:
    - un groupe "gSync" avec trois boutons:"Sync", "Settings" et "Help"
    - un groupe "Sync Actions" avec 5 boutons dont un bouton "Sync Calendars"

    Comment faire en VBA Outlook (depuis une macro) pour déclencher un click du bouton "Sync" ou du bouton "Sync Calendars"?

    Merci d'avance.

    Salutations.

  2. #2
    Expert éminent
    Avatar de Oliv-
    Homme Profil pro
    solution provider
    Inscrit en
    Mars 2006
    Messages
    4 087
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : solution provider

    Informations forums :
    Inscription : Mars 2006
    Messages : 4 087
    Points : 7 168
    Points
    7 168
    Billets dans le blog
    20
    Par défaut
    Bonjour,
    Essaye avec ce code
    il faut ajouter une référence à UIAutomationClient

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    Option Explicit
     
    Dim oAppCible
     
     
    Sub TEST_SelectRibbonTab()
        If UCase(Application) = "OUTLOOK" Then
            Set oAppCible = Application
        Else
            Set oAppCible = CreateObject("outlook.application")
        End If
    Call SelectRibbonTab("gSyncit")
    Call ClicButton("Sync Calendars")
     
    End Sub
     
     
    Public Sub SelectRibbonTab(NAME)
        Dim uiAuto As UIAutomationClient.CUIAutomation
        Dim elmRibbon As UIAutomationClient.IUIAutomationElement
        Dim elmRibbonTab As UIAutomationClient.IUIAutomationElement
        Dim cndProperty As UIAutomationClient.IUIAutomationCondition
        Dim aryRibbonTab As UIAutomationClient.IUIAutomationElementArray
        Dim ptnAcc As UIAutomationClient.IUIAutomationLegacyIAccessiblePattern
        Dim accRibbon As Office.IAccessible
        Dim i As Long
     
        Set elmRibbonTab = Nothing    '???
        Set uiAuto = New UIAutomationClient.CUIAutomation
     
     
        If InStr(1, oAppCible.NAME, "Outlook", vbTextCompare) > 0 Then
            If TypeName(oAppCible.ActiveWindow) = "Inspector" Then
                Set accRibbon = oAppCible.activeinspector.CommandBars("Ribbon")
            ElseIf TypeName(oAppCible.ActiveWindow) = "Explorer" Then
                Set accRibbon = oAppCible.activeexplorer.CommandBars("Ribbon")
            End If
        Else
            Set accRibbon = oAppCible.CommandBars("Ribbon")
        End If
        Set elmRibbon = uiAuto.ElementFromIAccessible(accRibbon, 0)
        Set cndProperty = uiAuto.CreatePropertyCondition(UIA_ClassNamePropertyId, "NetUIRibbonTab")
        Set aryRibbonTab = elmRibbon.FindAll(TreeScope_Subtree, cndProperty)
     
        For i = 0 To aryRibbonTab.Length - 1
            Set elmRibbonTab = aryRibbonTab.GetElement(i)
            If Not elmRibbonTab Is Nothing Then
                If elmRibbonTab.CurrentControlType = UIA_TabItemControlTypeId And StrComp(elmRibbonTab.CurrentName, NAME, vbTextCompare) = 0 Then
                    Set ptnAcc = elmRibbonTab.GetCurrentPattern(UIA_LegacyIAccessiblePatternId)
                    ptnAcc.DoDefaultAction
                    DoEvents
                    Exit For
                End If
            End If
        Next
     
        If ptnAcc Is Nothing Then
     
     
        End If
     
    End Sub
     
    Public Sub ClicButton(ByVal BoutonName As String)
     
        Dim uiAuto As UIAutomationClient.CUIAutomation
        Dim elmRibbon As UIAutomationClient.IUIAutomationElement
        Dim elmRibbonTab As UIAutomationClient.IUIAutomationElement
        Dim cndProperty As UIAutomationClient.IUIAutomationCondition
        Dim aryRibbonTab As UIAutomationClient.IUIAutomationElementArray
        Dim ptnAcc As UIAutomationClient.IUIAutomationLegacyIAccessiblePattern
        Dim accRibbon As Office.IAccessible
        Dim i As Long
     
        Set elmRibbonTab = Nothing    '???
        Set uiAuto = New UIAutomationClient.CUIAutomation
        Set accRibbon = oAppCible.activeexplorer.CommandBars("Ribbon")
        Set elmRibbon = uiAuto.ElementFromIAccessible(accRibbon, 0)
        '  Set cndProperty = uiAuto.CreatePropertyCondition(UIA_ClassNamePropertyId, "NetUIRibbonTab")
        Set cndProperty = uiAuto.CreatePropertyCondition(UIA_ClassNamePropertyId, "NetUIRibbonButton")
     
        Set aryRibbonTab = elmRibbon.FindAll(TreeScope_Subtree, cndProperty)
        For i = 0 To aryRibbonTab.Length - 1
            Debug.Print aryRibbonTab.GetElement(i).CurrentName
            If aryRibbonTab.GetElement(i).CurrentName = BoutonName Then
                Set elmRibbonTab = aryRibbonTab.GetElement(i)
                Exit For
            End If
        Next
        If elmRibbonTab Is Nothing Then Exit Sub
     
        Set ptnAcc = elmRibbonTab.GetCurrentPattern(UIA_LegacyIAccessiblePatternId)
        ptnAcc.DoDefaultAction
    End Sub

  3. #3
    Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2017
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Service public

    Informations forums :
    Inscription : Octobre 2017
    Messages : 2
    Points : 2
    Points
    2
    Par défaut
    Bonjour,

    Un grand merci.

    Le code fonctionne parfaitement et du premier coup (aucune modification à faire).

    Je l'ai intégré avec un timer qui le déclenche toutes les 5 minutes.
    Le clic se fait bien sur le bon bouton et le calendrier est synchronisé.

    Salutations.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Rester sur l'onglet actif après avoir cliquer sur un bouton submit
    Par gasquy dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 13/10/2011, 08h56
  2. envoyer un mél lorsque l'on cliquer sur un bouton
    Par mademoizel dans le forum ASP
    Réponses: 8
    Dernier message: 22/03/2007, 11h36
  3. cliquer sur un bouton seulement si on est membre
    Par leroidje dans le forum Langage
    Réponses: 3
    Dernier message: 09/11/2006, 06h46
  4. Réponses: 2
    Dernier message: 07/06/2006, 09h29
  5. cliquer sur un bouton d'une application extérieure
    Par looc 6699 dans le forum API, COM et SDKs
    Réponses: 7
    Dernier message: 12/12/2005, 17h46

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo