VBA - How to search via clipboard ?

K

Krzys(R)

Hi,
is sombody aware how to search for a string in content of clipboard
without writting it into a document.

Script that I'm writting has to get data from other program via
clipboard.
The header of it is allways the same "This is bla-bla file..."
I know how to check if clipboard is empty but no idea how to search
through it.
I though about Split() but data are huge and I don't fancy to create an
array with 10k records in it.

any help wellcome
kris
 
K

Karl E. Peterson

Krzys(R) said:
is sombody aware how to search for a string in content of clipboard
without writting it into a document.

You'll need to read the text into a variable, then.
The header of it is allways the same "This is bla-bla file..."

I'd recommend using Instr, in that case, after you've copied the clipboard data.
I know how to check if clipboard is empty but no idea how to search
through it.

Take a look at http://vb.mvps.org/samples/ClipEx for an emulation of VB's Clipboard
object written to be used in VBA. Within the CClipboard class, you'll find a GetText
method that ought to do nicely. Here's the meat of it:

Public Function GetText() As String
Dim nFmt As Long
Dim hData As Long
Dim lpData As Long

' Check for desired format.
nFmt = Me.GetPriorityFormat(CF_TEXT, CF_UNICODETEXT, CF_OEMTEXT, CF_DSPTEXT)

' -1=None requested, 0=Empty
If nFmt > 0 Then
' Grab text from clipboard, if available.
If OpenClipboard(0&) Then
hData = GetClipboardData(nFmt)
' Slurp characters from global memory.
If hData Then
lpData = GlobalLock(hData)
If nFmt = CF_UNICODETEXT Then
GetText = PointerToStringW(lpData)
Else
GetText = PointerToStringA(lpData)
End If
Call GlobalUnlock(hData)
End If
Call CloseClipboard
End If
End If
End Function

Later... Karl
 

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