Click here to Skip to main content
Licence CPOL
First Posted 27 Dec 2000
Views 37,061
Bookmarked 10 times

Multiple Clipboard Macros

By | 24 Jan 2001 | Article
Three simple macros that work together to add multiple clipboard functionality to Microsoft Visual C++.

These three simple macros work together to add multiple clipboard functionality to Microsoft Visual C++. Along with macros in the macro file you will find a couple of global variables. The most important one is a buffer used to collect up to 5 selections. MCopy adds the current selection to the end of the buffer. MPaste pastes the last copied string to the document and makes it selected. If you then execute MPaste again it takes another string from the buffer and replaces the previously pasted string. You can execute MPaste as many times as you want until you decide which selection to keep. And finally MClear resets the buffer. Enjoy!

'============== Multiple Clipboard Macros By Michael Pelts ========================

Dim buffer(4)
Dim nCopy
nCopy = 0
Dim nPaste
nPaste = 0
Dim nBufferSize
nBufferSize = 0

Sub MCopy ()
'DESCRIPTION: Multiple clipboard - copy
    if ActiveDocument Is Nothing Then
        Exit Sub
    elseif ActiveDocument.Type <> "Text" Then
        Exit Sub
    elseif Len(ActiveDocument.Selection) > 3060 Then
        MsgBox("Too long selectection")
        Exit Sub
    elseif Len(ActiveDocument.Selection) = 0 Then
        Exit Sub
    End If

    ActiveDocument.Selection.Copy
    buffer(nCopy) = ActiveDocument.Selection

    nPaste = nCopy
    nCopy = nCopy + 1
    
    if nCopy > 4 then 
        nCopy = 0
    End If

    if nBufferSize < 5 then
        nBufferSize = nBufferSize + 1
    end if
End Sub

'==================================================================

Sub MPaste ()
'DESCRIPTION: Multiple clipboard - paste
    ' Be sure active document is a text document
    if ActiveDocument Is Nothing Then
        Exit Sub
    elseif ActiveDocument.Type <> "Text" Then
        Exit Sub
    End If

    if nBufferSize = 0 then
        MsgBox("Empty buffer")
        Exit Sub
    End If

    ActiveDocument.Selection = ""
    Dim curCol
    Dim curLine
    curCol = ActiveDocument.Selection.CurrentColumn
    curLine = ActiveDocument.Selection.CurrentLine
    
    'get rid of new lines to obtain actulal string lenght
    tempPasteStr = buffer(nPaste)
    tempPasteStr = Replace(tempPasteStr, string(1, vbCr), "")

    Dim pasteStrLen
    pasteStrLen = Len(tempPasteStr)
    ActiveDocument.Selection = buffer(nPaste)

    if pasteStrLen < 400 then
        ActiveDocument.Selection.MoveTo curLine, curCol
        ActiveDocument.Selection.CharRight dsExtend, pasteStrLen
    end if
    
    nPaste = nPaste + 1    
    if nPaste >= nBufferSize then 
        nPaste = 0
    End If
End Sub

'==================================================================

Sub MClear ()
'DESCRIPTION: Resets the buffer.
    nCopy = 0
    nPaste = 0
    nBufferSize = 0
End Sub


'==================================================================

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Michael Pelts



United States United States

Member

Apply for Discover Motiva Card

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMultiple Clipboard PinmemberKlaus Stein20:59 2 Jan '01  
GeneralRe: Multiple Clipboard PinmemberXavier0:58 21 Feb '01  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 25 Jan 2001
Article Copyright 2000 by Michael Pelts
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid