ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to read previous copy selection address (https://www.excelbanter.com/excel-programming/434452-how-read-previous-copy-selection-address.html)

Adax

How to read previous copy selection address
 
Hallo! I'm looking for solution how to read previous copy selection address.
Is it possible in VBA in excel?
For instance:
1. select A1:B4
2. Ctrl + C
3 select G5
4 How to read this previous copy selection address (A1:B4)?
Thanks for any help, Adax


JLGWhiz[_2_]

How to read previous copy selection address
 
On the menu bar:

EditOffice Clipboard

It appears in a panel window on the right of the screen.


"Adax" wrote in message ...
Hallo! I'm looking for solution how to read previous copy selection
address. Is it possible in VBA in excel?
For instance:
1. select A1:B4
2. Ctrl + C
3 select G5
4 How to read this previous copy selection address (A1:B4)?
Thanks for any help, Adax




Bernie Deitrick

How to read previous copy selection address
 
Adax,

VBA does not have a method to address non-string values of the clipboard.
But you can set up an event to capture the copy or cut - within a workbook,
but not between workbooks - and have that value available. Copy this
(somewhat tested, but not fully tested) code into the ThisWorkbook
codemodule:

Option Explicit
Dim myAdd1 As String
Dim myAdd2 As String
Dim CCAdd As String
Dim WasNotCopy As Boolean

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Range)

If myAdd1 < "" Then
myAdd2 = myAdd1
myAdd1 = Target.Address(True, True, xlA1, True)
Else
myAdd1 = Target.Address(True, True, xlA1, True)
myAdd2 = myAdd1
End If

If (Application.CutCopyMode = xlCopy Or _
Application.CutCopyMode = xlCut) And WasNotCopy Then
MsgBox "Clipboard has " & CCAdd
End If
If (Application.CutCopyMode = xlCopy Or _
Application.CutCopyMode = xlCut) And Not WasNotCopy Then
CCAdd = myAdd2
MsgBox "Clipboard has " & CCAdd
WasNotCopy = True
End If
If Application.CutCopyMode = False Then WasNotCopy = False
End Sub


HTH,
Bernie
MS Excel MVP


"Adax" wrote in message ...
Hallo! I'm looking for solution how to read previous copy selection
address. Is it possible in VBA in excel?
For instance:
1. select A1:B4
2. Ctrl + C
3 select G5
4 How to read this previous copy selection address (A1:B4)?
Thanks for any help, Adax



Adax

How to read previous copy selection address
 
Użytkownik "Bernie Deitrick" <deitbe @ consumer dot org napisał w
wiadomości ...
Adax,
VBA does not have a method to address non-string values of the clipboard.
But you can set up an event to capture the copy or cut - within a
workbook, but not between workbooks - and have that value available. Copy
this (somewhat tested, but not fully tested) code into the
ThisWorkbook codemodule:
Option Explicit
Dim myAdd1 As String
Dim myAdd2 As String
Dim CCAdd As String
Dim WasNotCopy As Boolean
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal
Target As Range)
If myAdd1 < "" Then
myAdd2 = myAdd1
myAdd1 = Target.Address(True, True, xlA1, True)
Else
myAdd1 = Target.Address(True, True, xlA1, True)
myAdd2 = myAdd1
End If
If (Application.CutCopyMode = xlCopy Or _
Application.CutCopyMode = xlCut) And WasNotCopy Then
MsgBox "Clipboard has " & CCAdd
End If
If (Application.CutCopyMode = xlCopy Or _
Application.CutCopyMode = xlCut) And Not WasNotCopy Then
CCAdd = myAdd2
MsgBox "Clipboard has " & CCAdd
WasNotCopy = True
End If
If Application.CutCopyMode = False Then WasNotCopy = False
End Sub
HTH,
Bernie
MS Excel MVP


Thank You very much! :)



All times are GMT +1. The time now is 05:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com