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

Macros et VBA Excel Discussion :

Problème sur presse papier [XL-2007]


Sujet :

Macros et VBA Excel

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    473
    Détails du profil
    Informations personnelles :
    Localisation : France, Vendée (Pays de la Loire)

    Informations forums :
    Inscription : Novembre 2007
    Messages : 473
    Points : 493
    Points
    493
    Par défaut Problème sur presse papier
    Bonjour le forum,

    Depuis windows 8 j'ai un souci il me sort des point interrogations (??)

    Voici le code que j'utilise:

    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
    Dim ligne As Long
    Dim x
    Dim MaVariable As String
    Dim Temp As Integer
    Dim NumPiece As Variant
     
    Temp = CompTeur
     
    ligne = ActiveCell.Row
     
     
     
     
     
    MaVariable = "FA-" & Right(ActiveSheet.Cells(ligne, 1), 3) ' N° de facture
    With New DataObject ' pour coller dans le presse papier
     
    .SetText MaVariable
    .PutInClipboard
    End With
     
     
    Application.Wait Time + TimeSerial(0, 0, Temp + 2)
    ActiveSheet.Cells(ligne, 1).Interior.Color = &HFF00&
     
    ActiveSheet.Cells(ligne, 5).Interior.Color = &HFF0000
    MaVariable = ActiveSheet.Cells(ligne, 5) ' date
    With New DataObject ' pour coller dans le presse papier
    .SetText MaVariable
    .PutInClipboard
    End With
     
    ........
    ce fonctionnait très bien avant !??
    Cordialement,

    Jijie

  2. #2
    Expert éminent
    Homme Profil pro
    Inscrit en
    Août 2010
    Messages
    3 453
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Août 2010
    Messages : 3 453
    Points : 6 871
    Points
    6 871
    Par défaut
    Bonjour,

    Depuis windows 8 j'ai un souci il me sort des point interrogations (??)
    Il te les "sort" où et quel rapport avec le presse papier ?

    Hervé.

  3. #3
    Invité
    Invité(e)
    Par défaut
    Bonsoir,
    Intérêt de DataObject, est de placer le contenu d'une variable dans le presse papier! Toi du place le contenu d'une cellule dans une variable que tu place dans le presse papier!!!
    ActiveSheet.Cells(ligne, 5).copy ' date.

    Personnellement voila comment je fais:http://www.developpez.net/forums/d15...v/#post8305353
    Dernière modification par AlainTech ; 23/08/2015 à 11h47. Motif: Fusion de 2 messages

  4. #4
    Membre émérite
    Inscrit en
    Octobre 2010
    Messages
    1 401
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 1 401
    Points : 2 684
    Points
    2 684
    Par défaut
    Bonjour

    Citation Envoyé par jijie Voir le message
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    With New DataObject ' pour coller dans le presse papier
    .SetText MaVariable
    .PutInClipboard
    End With
    ce fonctionnait très bien avant !??
    En fait il y a un bug avec cette commande relié à Windows 8 et une mise à jour de Excel 2010, bug qui a été signalé à Microsoft.

    Ce bug remplace le texte par "??".
    Cordialement

    Docmarti.

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    473
    Détails du profil
    Informations personnelles :
    Localisation : France, Vendée (Pays de la Loire)

    Informations forums :
    Inscription : Novembre 2007
    Messages : 473
    Points : 493
    Points
    493
    Par défaut
    Bonjour,


    Je reviens sur ce post un peu tardivement !

    Docmarti, tu me signale:

    En fait il y a un bug avec cette commande relié à Windows 8 et une mise à jour de Excel 2010, bug qui a été signalé à Microsoft.

    Ce bug remplace le texte par "??".
    Peut-on trouver une solution pour rectifier ce bug? car effectivement j'utilise désormais windows 10
    Cordialement,

    Jijie

  6. #6
    Membre émérite
    Inscrit en
    Octobre 2010
    Messages
    1 401
    Détails du profil
    Informations forums :
    Inscription : Octobre 2010
    Messages : 1 401
    Points : 2 684
    Points
    2 684
    Par défaut
    Pour Office 2010 et 2013, on semble recommander d'utiliser plutôt l'API de Windows pour mettre du texte dans le Presse-papier
    https://msdn.microsoft.com/en-us/lib...ffice.14).aspx
    Cordialement

    Docmarti.

  7. #7
    Inactif  

    Homme Profil pro
    cuisiniste
    Inscrit en
    Avril 2009
    Messages
    15 379
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : cuisiniste
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2009
    Messages : 15 379
    Points : 12 075
    Points
    12 075
    Billets dans le blog
    8
    Par défaut heu
    Bonsoir
    c'est un bug assez récurent depuis vista

    j'ai souvent eu le soucis avec W7

    utiliser l'object en late binding semble coriger le soucis en utilisant son CLISD

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    Const DATAOBJECT_BINDING As String = "new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}"
     
    Sub Copy(ByVal Expression As String)
        With CreateObject(DATAOBJECT_BINDING)
     'RESTE DU CODE !!!!
    mes fichiers dans les contributions:
    mail avec CDO en vba et mail avec CDO en vbs dans un HTA
    survol des bouton dans userform
    prendre un cliché d'un range

    si ton problème est résolu n'oublie pas de pointer : : ça peut servir aux autres
    et n'oublie pas de voter

  8. #8
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    473
    Détails du profil
    Informations personnelles :
    Localisation : France, Vendée (Pays de la Loire)

    Informations forums :
    Inscription : Novembre 2007
    Messages : 473
    Points : 493
    Points
    493
    Par défaut
    Salut Patrick

    je n'arrive pas à placer mon code avec ta fonction!

    Tu fais ça comment?

    Pour info j'ai fait:

    Ds un module:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Option Explicit
    Const DATAOBJECT_BINDING As String = "new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}"
     
     
    Sub Copy1(ByVal Expression As String)
       With CreateObject(DATAOBJECT_BINDING)
            .SetText Expression
            .PutInClipboard
        End With
    End Sub
    et mon code:

    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
    Dim ligne As Long
    Dim x
    Dim MaVariable As String
    Dim Temp As Integer
    Dim NumPiece As Variant
     
    Temp = CompTeur
     
    ligne = ActiveCell.Row
     
     
     
     
     
    MaVariable = "FA-" & Right(ActiveSheet.Cells(ligne, 1), 3) ' N° de facture
     
    copy1 MaVariable
     
    Application.Wait Time + TimeSerial(0, 0, Temp + 2)
    ActiveSheet.Cells(ligne, 1).Interior.Color = &HFF00&
     
    ActiveSheet.Cells(ligne, 5).Interior.Color = &HFF0000
    MaVariable = ActiveSheet.Cells(ligne, 5) ' date
     
    copy1 MaVariable
     
    ........
    et toujours des "??"
    Cordialement,

    Jijie

  9. #9
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    473
    Détails du profil
    Informations personnelles :
    Localisation : France, Vendée (Pays de la Loire)

    Informations forums :
    Inscription : Novembre 2007
    Messages : 473
    Points : 493
    Points
    493
    Par défaut
    Citation Envoyé par Docmarti Voir le message
    Pour Office 2010 et 2013, on semble recommander d'utiliser plutôt l'API de Windows pour mettre du texte dans le Presse-papier
    https://msdn.microsoft.com/en-us/lib...ffice.14).aspx
    Bonsoir Docmarti,

    Cette version fonctionne parfaitement!!

    Ds un module
    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
    Option Explicit
     
    Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) _
       As Long
    Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) _
       As Long
    Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, _
       ByVal dwBytes As Long) As Long
    Declare Function CloseClipboard Lib "User32" () As Long
    Declare Function OpenClipboard Lib "User32" (ByVal hwnd As Long) _
       As Long
    Declare Function EmptyClipboard Lib "User32" () As Long
    Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, _
       ByVal lpString2 As Any) As Long
    Declare Function SetClipboardData Lib "User32" (ByVal wFormat _
       As Long, ByVal hMem As Long) As Long
     
    Public Const GHND = &H42
    Public Const CF_TEXT = 1
    Public Const MAXSIZE = 4096
     
     
    Function Copy1(MyString As String)
       Dim hGlobalMemory As Long, lpGlobalMemory As Long
       Dim hClipMemory As Long, X As Long
     
       ' Allocate moveable global memory.
       '-------------------------------------------
       hGlobalMemory = GlobalAlloc(GHND, Len(MyString) + 1)
     
       ' Lock the block to get a far pointer
       ' to this memory.
       lpGlobalMemory = GlobalLock(hGlobalMemory)
     
       ' Copy the string to this global memory.
       lpGlobalMemory = lstrcpy(lpGlobalMemory, MyString)
     
       ' Unlock the memory.
       If GlobalUnlock(hGlobalMemory) <> 0 Then
          MsgBox "Impossible de déverrouiller emplacement de mémoire. Copie abandonnée."
          GoTo OutOfHere2
       End If
     
       ' Open the Clipboard to copy data to.
       If OpenClipboard(0&) = 0 Then
          MsgBox "Impossible d'ouvrir le Presse-papiers. Copie avorté"
          Exit Function
       End If
     
       ' Clear the Clipboard.
       X = EmptyClipboard()
     
       ' Copy the data to the Clipboard.
       hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)
     
    OutOfHere2:
     
       If CloseClipboard() = 0 Then
          MsgBox "Impossible de fermer le Presse-papiers."
       End If
     
       End Function
    et le code comme mon post précédent!

    Merci à vous 2!!

    PS : Patrick pour te mettre 1 point, j'attends ta réponse!!
    Cordialement,

    Jijie

  10. #10
    Inactif  

    Homme Profil pro
    cuisiniste
    Inscrit en
    Avril 2009
    Messages
    15 379
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : cuisiniste
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2009
    Messages : 15 379
    Points : 12 075
    Points
    12 075
    Billets dans le blog
    8
    Par défaut re
    bonjour
    voudrais tu bien essayer ceci:
    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
    Const DATAOBJECT_BINDING As String = "new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}"
    Sub trucbidule()
     
        Dim MEMO As Object
        Set MEMO = CreateObject(DATAOBJECT_BINDING)
        Dim SEGMENTTEXT As String
        On Error GoTo hophophop
     
        MEMO.SetText "0 + 0 = "
        MEMO.PutInClipboard
        MEMO.GetFromClipboard
        SEGMENTTEXT = MEMO.GetText(1)
        MEMO.SetText " la tete a toto"
        MEMO.PutInClipboard
        ' recupère les datas du clipboard
        MsgBox SEGMENTTEXT & MEMO.GetText(1)
    hophophop:
        If Err <> 0 Then
            MsgBox "y a rien la dedans !!!! "
        End If
        Set MEMO = Nothing
    End Sub
    mes fichiers dans les contributions:
    mail avec CDO en vba et mail avec CDO en vbs dans un HTA
    survol des bouton dans userform
    prendre un cliché d'un range

    si ton problème est résolu n'oublie pas de pointer : : ça peut servir aux autres
    et n'oublie pas de voter

  11. #11
    Membre habitué Avatar de Le Sage
    Homme Profil pro
    Formateur Conseil en Bureautique et CMS, Développeur VBA, Power Query, Power Pivot
    Inscrit en
    Novembre 2009
    Messages
    210
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Formateur Conseil en Bureautique et CMS, Développeur VBA, Power Query, Power Pivot
    Secteur : Conseil

    Informations forums :
    Inscription : Novembre 2009
    Messages : 210
    Points : 171
    Points
    171
    Par défaut
    Bonjour.

    Bien que le sujet soit fermé, je poste cette réponse pour ceux qui cherchent encore à comprendre ce problème.

    En fait le problème est lié à l'explorateur Windows.
    Lorsqu'il est ouvert, on obtient ?? au collage, lorsqu'il est fermé on retrouve bien le contenu.
    Je l'ai signalé il y a des mois à Microsoft, j'attends toujours qu'ils se décident à mettre leur dll à jour.

    Pour ce qui est du code proposé sur docs.microsoft concernant l'utilisation de l'API Windows, il est obsolète (incompatible avec VB7), et j'en cherche désespérément une mise-à-jour.
    Ils ne savaient pas que c'était impossible, alors ils l'ont fait. (Mark TWAIN)

  12. #12
    Expert éminent
    Avatar de jurassic pork
    Homme Profil pro
    Bidouilleur
    Inscrit en
    Décembre 2008
    Messages
    3 954
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Bidouilleur
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2008
    Messages : 3 954
    Points : 9 284
    Points
    9 284
    Par défaut
    Hello,
    Citation Envoyé par Le Sage Voir le message
    Pour ce qui est du code proposé sur docs.microsoft concernant l'utilisation de l'API Windows, il est obsolète (incompatible avec VB7), et j'en cherche désespérément une mise-à-jour.
    Voici un code normalement compatible VBA7 :
    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
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    Option Explicit
    #If Mac Then
        ' ignore
    #Else
        #If VBA7 Then
            Declare PtrSafe Function GlobalUnlock Lib "kernel32" (ByVal hMem As LongPtr) As LongPtr
            Declare PtrSafe Function GlobalLock Lib "kernel32" (ByVal hMem As LongPtr) As LongPtr
            Declare PtrSafe Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, _
                                                                 ByVal dwBytes As LongPtr) As LongPtr
     
     
            Declare PtrSafe Function CloseClipboard Lib "user32" () As Long
            Declare PtrSafe Function OpenClipboard Lib "user32" (ByVal hwnd As LongPtr) As LongPtr
            Declare PtrSafe Function EmptyClipboard Lib "user32" () As Long
     
     
            Declare PtrSafe Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, _
                                                             ByVal lpString2 As Any) As LongPtr
     
     
            Declare PtrSafe Function SetClipboardData Lib "user32" (ByVal wFormat _
                                                                    As Long, ByVal hMem As LongPtr) As LongPtr
        #Else
            Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
            Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
            Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, _
                                                         ByVal dwBytes As Long) As Long
     
     
            Declare Function CloseClipboard Lib "user32" () As Long
            Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
            Declare Function EmptyClipboard Lib "user32" () As Long
     
     
            Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, _
                                                     ByVal lpString2 As Any) As Long
     
     
            Declare Function SetClipboardData Lib "user32" (ByVal wFormat _
                                                            As Long, ByVal hMem As Long) As Long
        #End If
    #End If
    Public Const GHND = &H42
    Public Const CF_TEXT = 1
    Public Const MAXSIZE = 4096
     
     
    Sub ClipBoard_SetData(MyString As String)
        #If Mac Then
            With New MSForms.DataObject
                .SetText MyString
                .PutInClipboard
            End With
        #Else
            #If VBA7 Then
                Dim hGlobalMemory As LongPtr
                Dim hClipMemory   As LongPtr
                Dim lpGlobalMemory    As LongPtr
            #Else
                Dim hGlobalMemory As Long
                Dim hClipMemory   As Long
                Dim lpGlobalMemory    As Long
            #End If
     
     
            Dim x                 As Long
     
     
            ' Allocate moveable global memory.
            '-------------------------------------------
            hGlobalMemory = GlobalAlloc(GHND, Len(MyString) + 1)
     
     
            ' Lock the block to get a far pointer
            ' to this memory.
            lpGlobalMemory = GlobalLock(hGlobalMemory)
     
     
            ' Copy the string to this global memory.
            lpGlobalMemory = lstrcpy(lpGlobalMemory, MyString)
     
     
            ' Unlock the memory.
            If GlobalUnlock(hGlobalMemory) <> 0 Then
                MsgBox "Could not unlock memory location. Copy aborted."
                GoTo OutOfHere2
            End If
     
     
            ' Open the Clipboard to copy data to.
            If OpenClipboard(0&) = 0 Then
                MsgBox "Could not open the Clipboard. Copy aborted."
                Exit Sub
            End If
     
     
            ' Clear the Clipboard.
            x = EmptyClipboard()
     
     
            ' Copy the data to the Clipboard.
            hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)
     
     
    OutOfHere2:
     
     
            If CloseClipboard() = 0 Then
                MsgBox "Could not close Clipboard."
            End If
        #End If
     
     
    End Sub
     
     
    Sub Test()
    ClipBoard_SetData "your text here"
    End Sub
    Ami calmant, J.P
    Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

  13. #13
    Rédacteur

    Homme Profil pro
    Administrateur de base de données
    Inscrit en
    Août 2013
    Messages
    947
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Administrateur de base de données
    Secteur : Finance

    Informations forums :
    Inscription : Août 2013
    Messages : 947
    Points : 4 058
    Points
    4 058
    Par défaut
    Bonjour JP.
    Il y a un double post sur le forum Général où l'auteur précise qu'il souhaite le SetData et le GetData, qui de plus marchent dans des conditions particulières.
    Je pense que son problème de compatibilité vient d'une version 64 bits, mais il ne dit rien sur sa version.

    Voici un code à tester:

    Code VBA : 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
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    Option Explicit
     
    '---------------------------------------------------------------------------------------
    ' https://msdn.microsoft.com/fr-fr/library/office/ff194373.aspx
    ' https://msdn.microsoft.com/fr-fr/library/office/ff192913.aspx
    '---------------------------------------------------------------------------------------
    '' API 64 bits:
    '' https://answers.microsoft.com/en-us/msoffice/forum/all/copy-paste-in-access-64-bit/2712f77c-03ec-4221-b4fe-d330379a58a3
    ''---------------------------------------------------------------------------------------
    #If Win64 Then
        Private Declare PtrSafe Function OpenClipboard Lib "User32" (ByVal hwnd As LongPtr) As LongPtr
        Private Declare PtrSafe Function EmptyClipboard Lib "User32" () As Long
        Private Declare PtrSafe Function SetClipboardData Lib "User32" (ByVal wFormat As Long, ByVal hMem As LongPtr) As LongPtr
        Private Declare PtrSafe Function CloseClipboard Lib "User32" () As Long
        Private Declare PtrSafe Function GetClipboardData Lib "user32.dll" (ByVal wFormat As Long) As Long
        Private Declare PtrSafe Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As LongPtr) As LongPtr
        Private Declare PtrSafe Function GlobalLock Lib "kernel32" (ByVal hMem As LongPtr) As LongPtr
        Private Declare PtrSafe Function GlobalUnlock Lib "kernel32" (ByVal hMem As LongPtr) As LongPtr
        Private Declare PtrSafe Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As LongPtr
    #Else
        Private Declare Function OpenClipboard Lib "User32" (ByVal hwnd As Long) As Long
        Private Declare Function EmptyClipboard Lib "user32.dll" () As Long
        Private Declare Function SetClipboardData Lib "user32.dll" (ByVal wFormat As Long, ByVal hMem As Long) As Long
        Private Declare Function CloseClipboard Lib "User32" () As Long
        Private Declare Function GetClipboardData Lib "User32" (ByVal wFormat As Long) As Long
        Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags&, ByVal dwBytes As Long) As Long
        Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
        Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
        Private Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
    #End If
    '---------------------------------------------------------------------------------------
    Private Const CF_TEXT = 1
    Private Const MAXSIZE = 65536
    Private Const GMEM_MOVEABLE = &H2
    Private Const GMEM_ZEROINIT = &H40
    Private Const GHND = (GMEM_MOVEABLE Or GMEM_ZEROINIT)
    '---------------------------------------------------------------------------------------
     
    '---------------------------------------------------------------------------------------
    Public Function ClipBoard_GetData() As String
    '---------------------------------------------------------------------------------------
    Dim hClipMemory As Long
    Dim lpClipMemory As Long
    Dim MyString As String
    Dim RetVal As Long
     
    If OpenClipboard(0&) = 0 Then '"Cannot open Clipboard. Another app. may have it open"
        Exit Function
    End If
     
    ' Obtain the handle to the global memory block that is referencing the text.
    hClipMemory = GetClipboardData(CF_TEXT)
    If IsNull(hClipMemory) Then '"Could not allocate memory"
        GoTo OutOfHere
    End If
     
    ' Lock Clipboard memory so we can reference the actual data string.
    lpClipMemory = GlobalLock(hClipMemory)
     
    If Not IsNull(lpClipMemory) Then
     
        MyString = Space$(MAXSIZE)
        RetVal = lstrcpy(MyString, lpClipMemory)
        RetVal = GlobalUnlock(hClipMemory)
     
        ' Gestion de la taille maximale du message à récupérer du clavier:
        If InStr(1, MyString, Chr$(0), 0) = 0 Then ' "Chaîne trop grande"
            Call CloseClipboard
            ClipBoard_GetData = ""
            Exit Function
        End If
     
        ' Peel off the null terminating character.
        MyString = Mid(MyString, 1, InStr(1, MyString, Chr$(0), 0) - 1)
     
    End If
     
    OutOfHere:
    RetVal = CloseClipboard()
    ClipBoard_GetData = MyString
     
    End Function
     
    '---------------------------------------------------------------------------------------
    Public Function ClipBoard_SetData(MyString As String) As Boolean
    '---------------------------------------------------------------------------------------
    '32-bit code by Microsoft: http://msdn.microsoft.com/en-us/library/office/ff192913.aspx
    Dim hGlobalMemory As LongPtr, lpGlobalMemory As LongPtr
    Dim hClipMemory As LongPtr, x As Long
     
    ' Gestion de la taille maximale du message a envoyer au clavier:
    If Len(MyString) >= MAXSIZE Then  ' "Chaîne trop grande"
        Exit Function
    End If
     
    ' Gestion des chaînes vides:
    If MyString = "" Then Exit Function
     
    ' Allocate moveable global memory.
    hGlobalMemory = GlobalAlloc(GHND, Len(MyString) + 1)
     
    ' Lock the block to get a far pointer to this memory.
    lpGlobalMemory = GlobalLock(hGlobalMemory)
     
    ' Copy the string to this global memory.
    lpGlobalMemory = lstrcpy(lpGlobalMemory, MyString)
     
    ' Unlock the memory.
    If GlobalUnlock(hGlobalMemory) <> 0 Then '"Could not unlock memory location. Copy aborted."
       GoTo OutOfHere
    End If
     
    ' Open the Clipboard to copy data to.
    If OpenClipboard(0&) = 0 Then ' "Could not open the Clipboard. Copy aborted."
       Exit Function
    End If
     
    ' Clear the Clipboard.
    x = EmptyClipboard()
     
    ' Copy the data to the Clipboard.
    hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)
     
    OutOfHere:
    If CloseClipboard() <> 0 Then
       ClipBoard_SetData = True
    End If
     
    End Function
    '---------------------------------------------------------------------------------------
    '---------------------------------------------------------------------------------------

    Cordialement

  14. #14
    Expert éminent
    Avatar de jurassic pork
    Homme Profil pro
    Bidouilleur
    Inscrit en
    Décembre 2008
    Messages
    3 954
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Bidouilleur
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2008
    Messages : 3 954
    Points : 9 284
    Points
    9 284
    Par défaut
    Citation Envoyé par Le Sage Voir le message
    Bien que le sujet soit fermé, je poste cette réponse pour ceux qui cherchent encore à comprendre ce problème.
    En fait le problème est lié à l'explorateur Windows.
    Lorsqu'il est ouvert, on obtient ?? au collage, lorsqu'il est fermé on retrouve bien le contenu.
    Je l'ai signalé il y a des mois à Microsoft, j'attends toujours qu'ils se décident à mettre leur dll à jour.
    Je n'arrive pas à reproduire le problème sur Office 2019 sous Windows 10 en utilisant DataObject. Alors avec quelle version de Office cela se produit -il ? Quel type (32 bits ou 64 bits) ? Quel O.S ? Et quelle est la version de la dll FM20.dll qui contient Microsoft Forms 2.0 Object Library (clic droit Propriétés/Détails) ?. Quel est le mode opératoire exact pour produire le problème ?
    Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

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

Discussions similaires

  1. [XL-2010] Problème vider presse papier
    Par Bobif dans le forum Macros et VBA Excel
    Réponses: 0
    Dernier message: 06/01/2015, 15h17
  2. Problème de presse papier
    Par koKoTis dans le forum Word
    Réponses: 4
    Dernier message: 19/09/2013, 23h13
  3. Word vers Publisher : problème de Presse-papiers
    Par Midas1422 dans le forum Microsoft Office
    Réponses: 0
    Dernier message: 28/02/2013, 16h29
  4. Copy et pasteSpecial lent ,problème de presse papier?
    Par nath-0-0 dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 08/06/2010, 11h11
  5. lire nom de fichier pour sauvegarde ensuite sur presse papier
    Par chapeau_melon dans le forum VBScript
    Réponses: 3
    Dernier message: 21/03/2007, 20h35

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