Click here to Skip to main content
12,635,802 members (26,424 online)
Click here to Skip to main content
Add your own
alternative version

Stats

40.3K views
10 bookmarked
Posted

Multiple Clipboard Macros

, 24 Jan 2001 CPOL
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author


You may also be interested in...

Comments and Discussions

 
GeneralMultiple Clipboard Pin
Klaus Stein2-Jan-01 21:59
memberKlaus Stein2-Jan-01 21:59 
GeneralRe: Multiple Clipboard Pin
Xavier21-Feb-01 1:58
memberXavier21-Feb-01 1:58 

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

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

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