RE/
Right - Excel tells the clipboard what formats it knows how to paste the
content as, and plan text is one of them. When you ask for the content as
plain text, Excel generates plain text.
That's much better than I hoped.
Oops... nothing's simple, I guess.
I'm using the GetClipboardData() API call and feeding it a parm of CF_TEXT.
Problem is that it's returning space-delimited instead of tab-delimited text
when there are spreadsheet columns/rows in the copy buffer.
Tried CF_SYLK, but got some sort of error message.
Wrong API call?
Plagerized from Dev Ashish's site with error trapping added, some variables
renamed and comments reworded:
--------------------------------------------------------------------
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags&, ByVal
dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal
lpString2 As Any) As Long
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString
As String) As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As
Long
Private Declare Function OpenClipboard Lib "user32" (ByVal Hwnd As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long)
As Long
Public Function ClipBoard_GetText() As String
1000 debugStackPush mModuleName & ": ClipBoard_GetText"
1001 On Error GoTo ClipBoard_GetText_err
' PURPOSE: To retreive clipboard's contents as text
' RETURNS: Tab/CRLF delimited text file containing contents of clipboard
1002 Dim hClipMemory As Long
Dim hClipDat As Long
Dim clipText As String
Dim returnValue As Long
Dim L As Long
1010 If OpenClipboard(0&) <> 0 Then
1020 hClipMemory = GetClipboardData(CF_TEXT) 'Get
handle to global memory block that is referencing the text.
1030 If hClipMemory <> 0 Then
1040 hClipDat = GlobalLock(hClipMemory) 'Lock
Clipboard memory so we can reference actual data.
1050 If hClipDat <> 0 Then
1051 L = GlobalSize(hClipDat)
1052 clipText = Space$(L)
1053 returnValue = lstrcpy(clipText, hClipDat)
1054 returnValue = GlobalUnlock(hClipMemory)
1055 clipText = Left(clipText, InStr(1, clipText, Chr$(0), 0) - 1) '
Strip null terminating character.
1056 Else
1057 bugAlert True, "Could not lock memory to copy string from.
ReturnValue='" & returnValue & "'."
1059 End If
1100 End If
1200 CloseClipboard
1300 End If
1999 ClipBoard_GetText = clipText
ClipBoard_GetText_xit:
debugStackPop
On Error Resume Next
Exit Function
ClipBoard_GetText_err:
bugAlert True, "ReturnValue='" & returnValue & "'."
Resume ClipBoard_GetText_xit
End Function
--------------------------------------------------------------------
--
PeteCresswell