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 :

Boîte de dialogue Word dans Outlook obligatoirement au premier plan


Sujet :

VBA Outlook

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Février 2009
    Messages
    100
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 100
    Points : 56
    Points
    56
    Par défaut Boîte de dialogue Word dans Outlook obligatoirement au premier plan
    Bonjour,

    J’utilise actuellement la fonction trouvée sur ce site
    Celle-ci me permet de pouvoir sélectionner un fichier grâce à la propriété msoFileDialogFilePicker que j’utilise à la place de la propriété msoFileDialogFolderPicker indiqué dans le script présenté sur le site.

    J’appelle donc cette fonction dans mon sub avec MsgBox GetFolderPathWithWord().
    Ça fonctionne bien, malheureusement régulièrement, la boîte de dialogue n’arrive pas au premier plan et donc bloque Outlook.
    La fenêtre est cachée derrière une autre fenêtre.

    J’ai essayé de rajouter l’option « VbMsgBoxSetForeground » à mon MsgBox mais cela ne semble pas fonctionner.
    Dans le cœur de la fonction, il y a l’option Set objOLWindow = objOL.ActiveWindow comme vous pouvez voir sur le site.

    Avez-vous une idée de comment je pourrai faire afin que cette boîte de dialogue arrive obligatoirement au premier plan ?

    Par avance, merci pour votre aide !

  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,
    voici une fonction équivalente utilisant Excel

    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
     
     
    Function BrowseFilesExplorer(Optional DialogTitle As String, _
                                 Optional ViewType As MsoFileDialogView = _
                                 MsoFileDialogView.msoFileDialogViewSmallIcons, _
                                 Optional InitialDirectory As String) As String
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Dim fDialog As Office.FileDialog
        Dim varFile As Variant
        Dim ExcelApp
        Set ExcelApp = CreateObject("Excel.application")
        ExcelApp.Visible = False
     
        'POUR METTRE EXCEL AU PREMIER PLAN
        Call ActiveExcelInvisible(ExcelApp.hwnd)
     
        Set fDialog = ExcelApp.FileDialog(msoFileDialogFilePicker)
        fDialog.InitialView = ViewType
        With fDialog
            .AllowMultiSelect = False
     
            If Dir(InitialDirectory, vbDirectory) <> vbNullString Then
                .InitialFileName = InitialDirectory & "\"
            Else
                .InitialFileName = CurDir
            End If
            .Title = DialogTitle
     
     
            Dim index
            index = .Filters.Count + 1
            'Add a filter that includes GIF and JPEG images and make it the second item in the list.
            .Filters.Add "Images", "*.gif; *.jpg; *.jpeg", index
            'Sets the initial file filter to index
            .FilterIndex = index
     
     
     
            If .Show = True Then
                ' user picked a file
                BrowseFilesExplorer = .SelectedItems(1)
            Else
                ' user cancelled
                BrowseFilesExplorer = vbNullString
            End If
        End With
        ExcelApp.Quit
    End Function
    A mettre en HAUT d'un MODULE
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    Declare Function SetForegroundWindow Lib "USER32" _
                                         (ByVal hwnd As Long) As Long
     
    Sub ActiveExcelInvisible(hwnd As Long)
        If hwnd = 0 Then Exit Sub
        SetForegroundWindow hwnd
    End Sub
    Pour tester
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Private Sub Test_BrowseFilesExplorer()
    ' *********** nouveau code pour avoir les raccourcis
    '  Appelle de la procédure d'affichage:
        MsgBox BrowseFilesExplorer("Choisir un fichier", msoFileDialogViewDetails, SDossier(0, 0))
     
    End Sub

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Février 2009
    Messages
    100
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 100
    Points : 56
    Points
    56
    Par défaut
    Bonjour,

    Haa mince, je pensai qu'il était possible de faire quelques chose avec cette fonction. Je vais devoir réadapter la fonction comme je l'avais personnalisé afin de correspondre à mon besoin.

    Merci, je vais tester et je reviens vers vous

    Haa et je suis en 64bits, ça va poser problème non avec le code ci-desous :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Declare Function SetForegroundWindow Lib "USER32" _
                                         (ByVal hwnd As Long) As Long
     
    Sub ActiveExcelInvisible(hwnd As Long)
        If hwnd = 0 Then Exit Sub
        SetForegroundWindow hwnd
    End Sub

  4. #4
    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
    Tu peux adapter pour WORD mais ce dernier ne donne pas son handle de fenêtre, il faut le chercher avec le nom de la FENETRE

    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
     
    '====================dans un module standard
    Public Declare Function FindWindow Lib "USER32" Alias "FindWindowA" _
                                       (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Declare Function SetForegroundWindow Lib "USER32" _
                                         (ByVal hwnd As Long) As Long
    Declare Function ShowWindow Lib "USER32" _
                                (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
     
     
    ' ShowWindow() Commands
    Public Const SW_HIDE = 0
    Public Const SW_SHOWNORMAL = 1
    Public Const SW_NORMAL = 1
    Public Const SW_SHOWMINIMIZED = 2
    Public Const SW_SHOWMAXIMIZED = 3
    Public Const SW_MAXIMIZE = 3
    Public Const SW_SHOWNOACTIVATE = 4
    Public Const SW_SHOW = 5
    Public Const SW_MINIMIZE = 6
    Public Const SW_SHOWMINNOACTIVE = 7
    Public Const SW_SHOWNA = 8
    Public Const SW_RESTORE = 9
    Public Const SW_SHOWDEFAULT = 10
    Public Const SW_MAX = 10
     
    Sub ActiveWord(Caption As String)
        Dim hwnd As Long
        hwnd = FindWindow(vbNullString, Caption)
     
        If hwnd = 0 Then Exit Sub
        SetForegroundWindow hwnd
        'ShowWindow hwnd, SW_SHOWMAXIMIZED
    End Sub
    dans ta macro avant Set dlg = objWord.FileDialog(msoFileDialogFolderPicker)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
            objWord.Caption = "WordFileDialog"
     
            If objWord.Documents.Count = 0 Then
     
            Call ActiveWord(objWord.Caption)
            Else
            Call ActiveWord(objWord.ActiveDocument.Name & " - " & objWord.Caption)
            End If
     
            'objWord.Visible = True
     
     
            ' show file dialog and handle users choice
            Set dlg = objWord.FileDialog(msoFileDialogFolderPicker)

    En général c'est ton Windows qui est en 64b et ton Office en 32b

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Février 2009
    Messages
    100
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 100
    Points : 56
    Points
    56
    Par défaut
    Merci ce je vais essayer ce dernier code avec la fonction utilisant word alors.

    Par contre, je confirme que j'ai une version 64bits d'Office donc j'ai des problèmes.

  6. #6
    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
    Pourquoi avoir choisi une version 64 bits de Office ?

  7. #7
    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
    regarde là le code

    http://www.developpez.net/forums/d14...s/#post7642480

    http://www.developpez.net/forums/d13...s-api-64-bits/

    ca donne

    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
    #If vba7 Then
        Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" _
                                    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
        Declare PtrSafe Function SetForegroundWindow Lib "user32" (ByVal hwnd As LongPtr) As Long
     
     Declare PtrSafe Function ShowWindow Lib "User32" (ByVal hWnd As LongPtr, ByVal nCmdShow As Long) As LongPtr
     
    #Else
     
        Declare Function FindWindow Lib "USER32" Alias "FindWindowA" _
                                       (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
       Declare Function SetForegroundWindow Lib "USER32" _
                                         (ByVal hwnd As Long) As Long
        Declare Function ShowWindow Lib "USER32" _
                                (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    #End If

  8. #8
    Membre du Club
    Profil pro
    Inscrit en
    Février 2009
    Messages
    100
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 100
    Points : 56
    Points
    56
    Par défaut
    Nous utilisons la version 64 bits car nous traitons de grands jeux de données notamment avec Excel avec des calculs complexes, des tableaux croisés dynamiques, des connexions de données,...

    Donc si je résume, je dois écrire ce code avec la déclaration des constantes au début de mon module (Public) :

    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
    #If vba7 Then
        Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" _
                                    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
        Declare PtrSafe Function SetForegroundWindow Lib "user32" (ByVal hwnd As LongPtr) As Long
     
     Declare PtrSafe Function ShowWindow Lib "User32" (ByVal hWnd As LongPtr, ByVal nCmdShow As Long) As LongPtr
     
    #Else
     
        Declare Function FindWindow Lib "USER32" Alias "FindWindowA" _
                                       (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
       Declare Function SetForegroundWindow Lib "USER32" _
                                         (ByVal hwnd As Long) As Long
        Declare Function ShowWindow Lib "USER32" _
                                (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    #End If
     
    ' ShowWindow() Commands
    Public Const SW_HIDE = 0
    Public Const SW_SHOWNORMAL = 1
    Public Const SW_NORMAL = 1
    Public Const SW_SHOWMINIMIZED = 2
    Public Const SW_SHOWMAXIMIZED = 3
    Public Const SW_MAXIMIZE = 3
    Public Const SW_SHOWNOACTIVATE = 4
    Public Const SW_SHOW = 5
    Public Const SW_MINIMIZE = 6
    Public Const SW_SHOWMINNOACTIVE = 7
    Public Const SW_SHOWNA = 8
    Public Const SW_RESTORE = 9
    Public Const SW_SHOWDEFAULT = 10
    Public Const SW_MAX = 10
     
    Sub ActiveWord(Caption As String)
        Dim hwnd As Long
        hwnd = FindWindow(vbNullString, Caption)
     
        If hwnd = 0 Then Exit Sub
        SetForegroundWindow hwnd
        'ShowWindow hwnd, SW_SHOWMAXIMIZED
    End Sub
    puis dans ma macro avant Set dlg = objWord.FileDialog(msoFileDialogFolderPicker) ajouter :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    objWord.Caption = "WordFileDialog"
     
            If objWord.Documents.Count = 0 Then
     
            Call ActiveWord(objWord.Caption)
            Else
            Call ActiveWord(objWord.ActiveDocument.Name & " - " & objWord.Caption)
            End If
     
            'objWord.Visible = True
     
     
            ' show file dialog and handle users choice
            Set dlg = objWord.FileDialog(msoFileDialogFolderPicker)
    C'est bien ça ?

    Si oui, merci beaucoup pour ton aide encore une fois!
    Je vais tester ça rapidement !

  9. #9
    Membre du Club
    Profil pro
    Inscrit en
    Février 2009
    Messages
    100
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 100
    Points : 56
    Points
    56
    Par défaut
    Bonjour Oliv',

    Je viens de tester et la code parait fonctionnel ! Merci !

    Je vais tester dans le temps afin de voir si je ne rencontre plus le problème comme je ne le rencontre pas en permanence.

    Peux-tu simplement me confirmer qu'avant ce code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    objWord.Caption = "WordFileDialog"
     
            If objWord.Documents.Count = 0 Then
     
            Call ActiveWord(objWord.Caption)
            Else
            Call ActiveWord(objWord.ActiveDocument.Name & " - " & objWord.Caption)
            End If
     
            'objWord.Visible = True
    je dois garder celui-ci en entier :
    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
        ' get active Outlook window
        Set objOL = CreateObject("Outlook.Application")
        Set objOLWindow = objOL.ActiveWindow
     
        ' start Word if necessary
        Set objWord = GetObject(, "Word.Application")
        If objWord Is Nothing Then
            Set objWord = CreateObject("Word.Application")
        End If
        If Not objWord Is Nothing Then
            ' get current Word window dimensions
            lngWidth = objWord.Width
            lngHeight = objWord.Height
            ' reduce size of Word window
            objWord.Width = 0
            objWord.Height = 0
            ' switch to Word
            objWord.Activate
    De plus, peux-tu m'expliquer réellement ce petit bout de code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    Sub ActiveWord(Caption As String)
        Dim hwnd As Long
        hwnd = FindWindow(vbNullString, Caption)
     
        If hwnd = 0 Then Exit Sub
        SetForegroundWindow hwnd
        'ShowWindow hwnd, SW_SHOWMAXIMIZED
    End Sub
    Merci

  10. #10
    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,

    il me semble que cette partie ne sert à rien, mais je n'ai pas l'ensemble de ton code.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
        ' get active Outlook window
        Set objOL = CreateObject("Outlook.Application")
        Set objOLWindow = objOL.ActiveWindow
    pour le code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    Sub ActiveWord(Caption As String)
        Dim hwnd As Long
     
    'ICI On cherche parmis les FENETRES DE WINDOWS (affichées ou non) celle qui se nomme comme le CAPTION
        hwnd = FindWindow(vbNullString, Caption)
     
    'SI LE FENETRE EST TROUVEE la valeur doit être différente de 0
        If hwnd = 0 Then Exit Sub
    'ON MET AU PREMIER PLAN LA FENETRE comme quand tu fait un alt+tab ou un clic sur ta fenetre
        SetForegroundWindow hwnd
    ' CA c'est POUR AGRANDIR/GERER LA TAILLE DE LA FENETRE
        'ShowWindow hwnd, SW_SHOWMAXIMIZED
    End Sub

  11. #11
    Membre du Club
    Profil pro
    Inscrit en
    Février 2009
    Messages
    100
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2009
    Messages : 100
    Points : 56
    Points
    56
    Par défaut
    Parfait, merci pour toutes ces explications !
    ça fonctionne bien

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

Discussions similaires

  1. Boîtes de dialogues fournies dans l'API
    Par seiryujay dans le forum Windows Presentation Foundation
    Réponses: 4
    Dernier message: 20/03/2009, 16h30
  2. Ramener Word (qui est ouvert) au premier plan
    Par Godzestla dans le forum Macros et VBA Excel
    Réponses: 6
    Dernier message: 21/05/2008, 10h47
  3. [mail] Word dans Outlook
    Par titiyo dans le forum Web & réseau
    Réponses: 7
    Dernier message: 30/11/2007, 10h47
  4. Réponses: 5
    Dernier message: 20/05/2006, 22h43
  5. [MFC] Dessiner dans une boîte de dialogue
    Par Philippe320 dans le forum MFC
    Réponses: 5
    Dernier message: 03/03/2006, 21h44

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