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 Access Discussion :

Récupérer le presse papier pour le décomposer sous forme de tableau [AC-2010]


Sujet :

VBA Access

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Août 2005
    Messages
    525
    Détails du profil
    Informations personnelles :
    Âge : 57
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Secteur : Santé

    Informations forums :
    Inscription : Août 2005
    Messages : 525
    Par défaut Récupérer le presse papier pour le décomposer sous forme de tableau
    Bonjour à tous

    Je tente en vain de récupérer le presse papier (dans lequel je copie un tableau) pour le découper et l'importer dans une table. Mais je bute au début !
    Impossible de faire fonctionner ce qui est conseillé dans l'aide d'Access

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    Function AfficherPressePapier()
     
    Dim MyData As DataObject
        MyData.GetFromClipboard
        MsgBox MyData.GetText(1)
    End Function
    Il bute sur DataObject non défini par l'utilisateur.
    Merci pour vos conseils.

  2. #2
    Expert éminent

    Avatar de Tofalu
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Octobre 2004
    Messages
    9 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Octobre 2004
    Messages : 9 501
    Par défaut
    Cette méthode s'applique aux userform mais pas aux formulaire d'Access. L'aide est trompeuse.

    Il faut préciser vos besoins pour définir une stratégie

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Août 2005
    Messages
    525
    Détails du profil
    Informations personnelles :
    Âge : 57
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Secteur : Santé

    Informations forums :
    Inscription : Août 2005
    Messages : 525
    Par défaut
    Ah les coquins !
    Je récupère un tableau dans le presse papier avec une colonne et plusieurs lignes
    Chaque ligne est composé de:

    Texte , Chiffre1 espace texte1, chiffre2 espace texte2, etc...

    Je veux alimenter une table avec
    Colonne 1: Texte
    Colonne 2: Chiffre1 Chiffre2 Chiffre3

    Il n'y aura probablement pas plus de 6 chiffres

    Mais déjà si je connaissais la syntaxe pour alimenter le tableau...
    Merci d'avance.

    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
     
     
    Sub CopyTextToClipboard(byval inText as String)
      Dim objClipboard As Object
      Set objClipboard = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
     
      objClipboard.SetText inText
      objClipboard.PutInClipboard
     
      Set objClipboard = Nothing
    End Sub
     
     
     
    Function GetTextFromClipboard() As String
      Dim objClipboard As Object
      Set objClipboard = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
     
      objClipboard.GetFromClipboard
      GetTextFromClipboard = objClipboard.GetText
     
      Set objClipboard = Nothing
    End Function
    Ce code est proposé mais il me renvoie "espace pile insuffisant"

  4. #4
    Membre éclairé
    Profil pro
    Inscrit en
    Août 2005
    Messages
    525
    Détails du profil
    Informations personnelles :
    Âge : 57
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Secteur : Santé

    Informations forums :
    Inscription : Août 2005
    Messages : 525
    Par défaut
    J'ai trouvé cette fonction qui me renvoie le texte du presse papier.

    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
     
    Option Compare Database
     
    '32-bit Declarations (for Access 95 and later). (16-bit version also available for Access 1 and 2.)
     
    Declare Function abOpenClipboard Lib "User32" Alias "OpenClipboard" (ByVal Hwnd As Long) As Long
    Declare Function abCloseClipboard Lib "User32" Alias "CloseClipboard" () As Long
    Declare Function abEmptyClipboard Lib "User32" Alias "EmptyClipboard" () As Long
    Declare Function abIsClipboardFormatAvailable Lib "User32" Alias "IsClipboardFormatAvailable" (ByVal wFormat As Long) As Long
    Declare Function abSetClipboardData Lib "User32" Alias "SetClipboardData" (ByVal wFormat As Long, ByVal hMem As Long) As Long
    Declare Function abGetClipboardData Lib "User32" Alias "GetClipboardData" (ByVal wFormat As Long) As Long
    Declare Function abGlobalAlloc Lib "Kernel32" Alias "GlobalAlloc" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
    Declare Function abGlobalLock Lib "Kernel32" Alias "GlobalLock" (ByVal hMem As Long) As Long
    Declare Function abGlobalUnlock Lib "Kernel32" Alias "GlobalUnlock" (ByVal hMem As Long) As Boolean
    Declare Function abLstrcpy Lib "Kernel32" Alias "lstrcpyA" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
    Declare Function abGlobalFree Lib "Kernel32" Alias "GlobalFree" (ByVal hMem As Long) As Long
    Declare Function abGlobalSize Lib "Kernel32" Alias "GlobalSize" (ByVal hMem As Long) As Long
    Const GHND = &H42
    Const CF_TEXT = 1
    Const APINULL = 0
     
    Function Clipboard2Text()
    'To paste from the clipboard:
        Dim wLen As Integer
        Dim hMemory As Long
        Dim hMyMemory As Long
     
        Dim lpMemory As Long
        Dim lpMyMemory As Long
     
        Dim retval As Variant
        Dim wFreeMemory As Boolean
        Dim wClipAvail As Integer
        Dim szText As String
        Dim wSize As Long
     
        If abIsClipboardFormatAvailable(CF_TEXT) = APINULL Then
            Clipboard2Text = Null
            Exit Function
        End If
     
        If abOpenClipboard(0&) = APINULL Then
            MsgBox "Unable to open Clipboard.  Perhaps some other application is using it."
            GoTo CB2T_Free
        End If
     
        hMemory = abGetClipboardData(CF_TEXT)
        If hMemory = APINULL Then
            MsgBox "Unable to retrieve text from the Clipboard."
            Exit Function
        End If
        wSize = abGlobalSize(hMemory)
        szText = Space(wSize)
     
        wFreeMemory = True
     
        lpMemory = abGlobalLock(hMemory)
        If lpMemory = APINULL Then
            MsgBox "Unable to lock clipboard memory."
            GoTo CB2T_Free
        End If
     
        ' Copy our string into the locked memory.
        retval = abLstrcpy(szText, lpMemory)
        ' Get rid of trailing stuff.
        szText = Trim(szText)
        ' Get rid of trailing 0.
        Clipboard2Text = Left(szText, Len(szText) - 1)
        wFreeMemory = False
     
     
    CB2T_Close:
        If abCloseClipboard() = APINULL Then
            MsgBox "Unable to close the Clipboard."
        End If
        If wFreeMemory Then GoTo CB2T_Free
        Exit Function
     
    CB2T_Free:
        If abGlobalFree(hMemory) <> APINULL Then
            MsgBox "Unable to free global clipboard memory."
        End If
    End Function
    Je travaille à présent sur le moyen de l'importer dans une table.

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

Discussions similaires

  1. Réponses: 1
    Dernier message: 20/04/2010, 16h59
  2. Récupérer le presse papier en temps réel
    Par scude dans le forum VB.NET
    Réponses: 0
    Dernier message: 17/01/2010, 12h34
  3. Réponses: 3
    Dernier message: 19/01/2008, 10h20
  4. Récupérer le presse-papier
    Par futneguet dans le forum C++
    Réponses: 6
    Dernier message: 10/08/2006, 12h40
  5. XSL pour visualiser arbre XML sous forme de tableau en HTML
    Par mattmat dans le forum XSL/XSLT/XPATH
    Réponses: 4
    Dernier message: 28/03/2003, 10h55

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