Microsoft 365 Vider presse Papier VBA

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

Nounours

XLDnaute Nouveau
Bonjour , je travaille sur Outlook 365 et je n'arrive pas à trouver le moyen di vider le presse papier .
J'ai un fichier qui fait de nombreux copier coller du coup le fichier excel rame .

J'ai déjà essayé sans succès les codes suivants :

Sub NettoyerPressePapiersExcel()
Application.CutCopyMode = False
End Sub

---------------------------

Option Explicit

Public Declare Function OuvrirPressePapiers Lib "user32" Alias "OpenClipboard" (ByVal hwnd As Long) As Long
Public Declare Function ViderPressePapiers Lib "user32" Alias "EmptyClipboard" () As Long
Public Declare Function FermerPressePapiers Lib "user32" Alias "CloseClipboard" () As Long

Public Function NettoyerPressePapiers()
OuvrirPressePapiers (0&)
ViderPressePapiers
FermerPressePapiers
End Function

---------------------------

Option Explicit

Public Declare PtrSafe Function OuvrirPressePapiers Lib "user32" Alias "OpenClipboard" (ByVal hwnd As Long) As LongPtr
Public Declare PtrSafe Function ViderPressePapiers Lib "user32" Alias "EmptyClipboard" () As LongPtr
Public Declare PtrSafe Function FermerPressePapiers Lib "user32" Alias "CloseClipboard" () As LongPtr

Public Function NettoyerPressePapiers()
OuvrirPressePapiers (0&)
ViderPressePapiers
FermerPressePapiers
End Function
 
Solution
Bonjour @Nounours, @job75
@Nounours , avec un fichier c'est toujours mieux ...
Voici le code pour optimiser vos copier-coller
VB:
    ' Votre code
    ' AVANT
    Workbooks(variables.classeur1).Sheets(variables.nomfeuille1).Range("B10", "C" & variables.Derligne).Copy
    Workbooks(variables.classeur2).Sheets(variables.nomfeuille2).Range("A" & variables.derlign).PasteSpecial Paste:=xlPasteValues
    'APRES
    Application.ScreenUpdating = False ' à positionner avant la série de copie
    Workbooks(variables.classeur1).Sheets(variables.nomfeuille1).Range("B10", "C" & variables.Derligne).Copy
    Workbooks(variables.classeur2).Sheets(variables.nomfeuille2).Range("A" & variables.derlign).PasteSpecial...
Bonjour le fil,
voir la fonction ClearPressePapier dans le code ci-dessous
VB:
Public Function ClearPressePapier()
    With CreateObject("htmlfile").parentWindow.clipboardData.clearData("Text"): End With
End Function
Public Property Let PressePapier(valeur)
    With CreateObject("htmlfile").parentWindow.clipboardData.SetData("Text", valeur): End With
End Property
Public Property Get PressePapier()
    PressePapier = CreateObject("htmlfile").parentWindow.clipboardData.GetData("TEXT")
End Property

Sub MettreDansPressePapier()
Dim Cumul As Long
Dim TextePressePapier As String
    Cumul = Application.Sum(Range("A2:A5"))
    TextePressePapier = "Le cumul ""A2:A5"" = " & CStr(Cumul)
    MsgBox "Le texte " & TextePressePapier & " est dans le Presse-papier." & vbCrLf & "Il peut être copié n'importe où.", vbInformation
    ClearPressePapier
    PressePapier = TextePressePapier  'se retrouve dans le pressePapier
End Sub
Sub InfosDansPressePapier()
Dim DerLigne As Integer
Dim TextePressePapier As String
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Sheets.Add After:=ActiveSheet
    For i = 1 To 10
        ActiveSheet.Cells(i, 1) = "Texte ligne " & i
    Next i
    DerLigne = ActiveSheet.Cells.Find("*", , , , xlByRows, xlPrevious).Row
    For i = 1 To DerLigne
        TextePressePapier = TextePressePapier & Cells(i, 1) & vbLf
    Next i
    ClearPressePapier
    PressePapier = TextePressePapier  'se retrouve dans le pressePapier
    ActiveSheet.Delete
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    MsgBox "Les informations système sont dans le Presse-papier.", vbInformation

End Sub
Sub InfosDansPressePapierbis()
Dim DerLigne As Integer
Dim TextePressePapier As String
Dim objCP As Object
Dim Message As String
    TextePressePapier = "Mon texte à copier dans le presse-papier."
    Set objCP = CreateObject("HtmlFile")
    objCP.parentWindow.clipboardData.SetData "text", TextePressePapier
    Message = "Le texte " & vbLf _
            & """" & objCP.parentWindow.clipboardData.GetData("text") & """" & vbLf _
            & "     est dans le Presse-papier."
    MsgBox Message, vbInformation
    Set objCP = Nothing
End Sub
 
Bonjour le fil,
voir la fonction ClearPressePapier dans le code ci-dessous
VB:
Public Function ClearPressePapier()
    With CreateObject("htmlfile").parentWindow.clipboardData.clearData("Text"): End With
End Function
Public Property Let PressePapier(valeur)
    With CreateObject("htmlfile").parentWindow.clipboardData.SetData("Text", valeur): End With
End Property
Public Property Get PressePapier()
    PressePapier = CreateObject("htmlfile").parentWindow.clipboardData.GetData("TEXT")
End Property

Sub MettreDansPressePapier()
Dim Cumul As Long
Dim TextePressePapier As String
    Cumul = Application.Sum(Range("A2:A5"))
    TextePressePapier = "Le cumul ""A2:A5"" = " & CStr(Cumul)
    MsgBox "Le texte " & TextePressePapier & " est dans le Presse-papier." & vbCrLf & "Il peut être copié n'importe où.", vbInformation
    ClearPressePapier
    PressePapier = TextePressePapier  'se retrouve dans le pressePapier
End Sub
Sub InfosDansPressePapier()
Dim DerLigne As Integer
Dim TextePressePapier As String
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Sheets.Add After:=ActiveSheet
    For i = 1 To 10
        ActiveSheet.Cells(i, 1) = "Texte ligne " & i
    Next i
    DerLigne = ActiveSheet.Cells.Find("*", , , , xlByRows, xlPrevious).Row
    For i = 1 To DerLigne
        TextePressePapier = TextePressePapier & Cells(i, 1) & vbLf
    Next i
    ClearPressePapier
    PressePapier = TextePressePapier  'se retrouve dans le pressePapier
    ActiveSheet.Delete
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    MsgBox "Les informations système sont dans le Presse-papier.", vbInformation

End Sub
Sub InfosDansPressePapierbis()
Dim DerLigne As Integer
Dim TextePressePapier As String
Dim objCP As Object
Dim Message As String
    TextePressePapier = "Mon texte à copier dans le presse-papier."
    Set objCP = CreateObject("HtmlFile")
    objCP.parentWindow.clipboardData.SetData "text", TextePressePapier
    Message = "Le texte " & vbLf _
            & """" & objCP.parentWindow.clipboardData.GetData("text") & """" & vbLf _
            & "     est dans le Presse-papier."
    MsgBox Message, vbInformation
    Set objCP = Nothing
End Sub
Bonjour Crocrocro ,

Je ne comprends pas bien ton code ,
Je ne vois pas pourquoi tu cumule les cases de A2 à A5
je vois bien l'ajout des textes mais lorsque je laisse le presse papier excel ouvert je ne le vois pas se vider .
 
bonjour @Nounours,
Comme vous n'aviez pas donné votre code, j'ai posté un exemple de manipulation du presse-papier.
C'est la ligne ClearPressePapier qui vous devez ajouter dans votre code après avoir fait votre coller depuis le presse-papier .
Crocrocro ,

Le but de mon fichier est de récupérer les pointages de l'ensemble du personnel pour chaque activité de chaque client ( 4 client avec en moyenne 3 actibvités chacun )

je te joint mon fichier car je ne vois pas comment insérer ton code
faut il que je fasse un appel à ton code à chaque fin de copier collé ( Call ClearPressePapier ) ou une fois apres chaque client suffirait ?

Je joints mon fichier pour voir mon code . ( mais il manque les planning )
 

Pièces jointes

Bonjour @Nounours, @job75
@Nounours , avec un fichier c'est toujours mieux ...
Voici le code pour optimiser vos copier-coller
VB:
    ' Votre code
    ' AVANT
    Workbooks(variables.classeur1).Sheets(variables.nomfeuille1).Range("B10", "C" & variables.Derligne).Copy
    Workbooks(variables.classeur2).Sheets(variables.nomfeuille2).Range("A" & variables.derlign).PasteSpecial Paste:=xlPasteValues
    'APRES
    Application.ScreenUpdating = False ' à positionner avant la série de copie
    Workbooks(variables.classeur1).Sheets(variables.nomfeuille1).Range("B10", "C" & variables.Derligne).Copy
    Workbooks(variables.classeur2).Sheets(variables.nomfeuille2).Range("A" & variables.derlign).PasteSpecial Paste:=xlPasteValues
    ' ....
    ' ....
    Application.CutCopyMode = False ' à positionner après la série de copie
    Application.ScreenUpdating = True ' à positionner après la série de copie
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
46
Affichages
2 K
Réponses
7
Affichages
525
Retour