<Parent> of the Clipboard

T

Tim Childs

Hi

Is it possible to determine the source filename of the contents of the
clipboard.

The reason I ask is that I am writing a utility for others to use for
re-arranging data in the clipboard prior to pasting that re-arrangement and
some of the code is dependent on the information gleaned from the
spreadsheet which is sitting in the clipboard.

Put another way:
a) user selects data (from one of three files) - puts it in clipboard
b) user selects destination in different speadsheet
c) user runs procedure which manipulates data (incl code dependent on the
one of three files chosen) and pastes it at the activecell

Any help very welcome.

Tim
 
G

Guest

You would need to use Windows API calls. Since the clipboard can hold
multiple items it is not straightforward unless you have a controlled
situation. The clipboard has an "owner" - per the documentation:
"In general, the clipboard owner is the window that last placed data in
clipboard."
(I love those "in general" qualifiers!)

But this only identifies the last app to have cut or copied data into the
clipboard. There are more advanced techniques involving creating and
registering your own clipboard formats that could be used, but would be very
advanced coding.

Full details:
http://msdn.microsoft.com/library/d...ndowsuserinterface/dataexchange/clipboard.asp
 
T

Tim Childs

Hi

thanks for this

based on the link
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui
/windowsuserinterface/dataexchange/clipboard/clipboardreference/clipboardfun
ctions/enumclipboardformats.asp
which includes:
The GetClipboardOwner function retrieves the window handle of the current
owner of the clipboard.

Syntax

HWND GetClipboardOwner( VOID
);I wrote in a code module:

Option Explicit

Sub foo()
HWND GetClipboardOwner(VOID)
End Sub

I tried writing this at the top of the code module but the compiler said it
was invalid outside a procedure but it still had problems inside one too :)

Any help v welcome

Tim
 
G

Guest

OK, didn't know if you were familiar with Windows API. Win API is a library
of functions. They are not "standard" in VBA, so you have to tell VBA where
to find them and how to use them. The documentation you quote tells you that
the function result is a HWND which is a "windows handle" - a number (Long
integer) that windows uses to identify a particular window that is open. It
also tells you that the parameters are VOID - in other words, there are no
parameters. The API documentation also tells you what the "import library" is
- what file contains the function (all those .dll files on your computer are
libraries) - and in this case it is User32.dll, which should be in your
standard Windows path.

To declare a library function in VBA you do it like this:

Declare Function GetClipboardOwner Lib "user32" () As Long

Then you can use it as any other function in VBA. But the result is a
window handle. That may not be useful to you. See this reference about
handles, which includes code to find a window's title bar text if you have
its handle:
http://msdn.microsoft.com/library/d...us/modcore/html/deovrunderstandinghandles.asp

For more on using the Windows API in general:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/modcore/html/deovrapibasics.asp

--
- K Dales


Tim Childs said:
Hi

thanks for this

based on the link
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui
/windowsuserinterface/dataexchange/clipboard/clipboardreference/clipboardfun
ctions/enumclipboardformats.asp
which includes:
The GetClipboardOwner function retrieves the window handle of the current
owner of the clipboard.

Syntax

HWND GetClipboardOwner( VOID
);I wrote in a code module:

Option Explicit

Sub foo()
HWND GetClipboardOwner(VOID)
End Sub

I tried writing this at the top of the code module but the compiler said it
was invalid outside a procedure but it still had problems inside one too :)

Any help v welcome

Tim
 
T

Tim Childs

Hi

Thanks for coming back with more explanation which I'll try to assimilate -
I am certainly feel a lot closer with your help. (Up to now, I have used
some API's but they've pretty much been off the shelf!)

Best wishes

Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top