Search code examples
vbaexcelexcel-2007clipboard

Copy / Paste in Excel using clipboard


After copying data from PDF using clipboard. I have three chunks of data in clipboard and I want to Paste each at different locations in Excel-2007 let's say:

  • Data in clipboard 3 should paste in A1

  • Data in clipboard 2 should paste in C1

  • Data in clipboard 1 should paste in E1

VBA code

 ActiveSheet.Paste 

is not working here, It will only paste the last thing copied. Is it possible to handle Clipboard using Excel VBA and how?

enter image description here


Solution

  • I have tried to copy some stuff to the clipboard and to paste it from there, using the macro recorder. Seeing the code, my opinion is that the answer of your question is "NO".

    Take a look at the code yourself, you will see that the clipboard position is not referenced at all:

    Sub Makro2()
    '
    ' Makro2 Makro
    '
    
    '
        Range("A2").Select
        Selection.Copy
        Range("A1").Select
        ActiveSheet.Paste
        Range("A3").Select
        Application.CutCopyMode = False
        Selection.Copy
        Range("A4").Select
        ActiveSheet.Paste
        Range("A5").Select
        Application.CutCopyMode = False
        Range("A4").Select
        Selection.Copy
        Range("A3").Select
        Application.CutCopyMode = False
        Selection.Copy
        Range("A2").Select
        Application.CutCopyMode = False
        Selection.Copy
        Range("A1").Select
        Application.CutCopyMode = False
        Selection.Copy
        Application.CutCopyMode = False
        Range("C4").Select
        ActiveSheet.Paste
        Range("C6").Select
        ActiveSheet.Paste
        Range("D13:D14").Select
        Range("D14").Activate
        ActiveSheet.Paste
        Range("C15").Select
        ActiveSheet.Paste
        ActiveSheet.Paste
        Range("A17").Select
        ActiveSheet.Paste
        Range("C18").Select
    End Sub