title image

Smiley Re: Office-Zwischenablage in Excel 2002
Hallo HPS2,

wenns dir reicht die Zwischenablage zu leeren, dann gehts so:

Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function EmptyClipboard Lib "user32" () As Long

Private Declare Function CloseClipboard Lib "user32" () As Long

Public Sub loeschen_Zwischenablage()

OpenClipboard FindWindow("xlMain", vbNullString)



End Sub

wenn du wissen willst was in der Zwischenablage drin ist, dann gehts so:

Code fur Modul1

Option Explicit


' Copyright ©1996-2006 VBnet, Randy Birch, All Rights Reserved.

' Some pages may also contain other copyrights by the author.


' Distribution: You can freely use this code in your own

' applications, but you may not reproduce

' or publish this code on any web site,

' online service, or distribute as source

' on any media without express permission.


Private Const CF_HDROP As Long = 15

Private Declare Function IsClipboardFormatAvailable Lib "user32" _

(ByVal uFormat As Long) As Long

Private Declare Function OpenClipboard Lib "user32" _

(ByVal hWndNewOwner As Long) As Long

Private Declare Function GetClipboardData Lib "user32" _

(ByVal uFormat As Long) As Long

Private Declare Sub CloseClipboard Lib "user32" ()

Private Declare Function DragQueryFile Lib "shell32.dll" _

Alias "DragQueryFileA" _

(ByVal hDrop As Long, _

ByVal iFile As Long, _

ByVal lpszFile As String, _

ByVal cch As Long) As Long

Private Declare Function lstrlenW Lib "kernel32" _

(ByVal lpString As Long) As Long

'Private Sub Form_Load()


' With List1

' .Move 200, 200, 5000, 2400

' .Clear

' End With


' With Command1

' .Move 200, List1.Top + List1.Height + 200, 2000, 345

' .Caption = "Get Clipboard File List"

' End With


'End Sub


'Private Sub Command1_Click()


' Call ClipboardGetFiles


'End Sub

Private Function ClipboardHasFiles() As Boolean

'CF_HDROP indicates that the clipboard

'identifies a list of files.

ClipboardHasFiles = (IsClipboardFormatAvailable(CF_HDROP) > 0)

End Function

Sub ClipboardGetFiles()

Dim hCBData As Long

Dim numFiles As Long

Dim cnt As Long

Dim cbBuff As Long

Dim buff As String

If ClipboardHasFiles() Then

If OpenClipboard(0&) 0 Then

'GetClipboardData returns a handle

'that identifies a list of files.

'The application retrieves this

'information by passing the handle

'to the DragQueryFile function.

hCBData = GetClipboardData(CF_HDROP)

If hCBData 0 Then

'the first call to DragQueryFile

'passes -1 as the iFile value; the

'api in return indicates the number

'of files to be dropped.

'note that once we're done we do not call

'DragFinish as we did nothing with the

'data other than list it.

numFiles = DragQueryFile(hCBData, -1, 0&, 0&)

'loop for each file ..

For cnt = 0 To numFiles - 1

'.. and each subsequent call to DragQueryFile

'returns info about the file specified by

'the iFile value. By passing null for the

'buffer and size, the required buffer size

'is returned.

cbBuff = DragQueryFile(hCBData, cnt, vbNullString, 0&)

If cbBuff > 0 Then

'pad the buffer adding one for

'the terminating null char

buff = Space$(cbBuff + 1)

cbBuff = Len(buff)

'the final call will return the file;

'the return value, not used here, is

'the size of the file string returned.

If DragQueryFile(hCBData, cnt, buff, cbBuff) > 0 Then

'just add to list for this demo

UserForm1.ListBox1.AddItem TrimNull(buff)

End If

End If

Next cnt

End If 'hCbData

Call CloseClipboard

End If 'OpenClipboard

End If 'ClipboardHasFiles

End Sub

und Code für eine Userfom1 mit einer listbox1 und einem Commandbutton1

dh. der Code ist dem Commandbutton zuzuweisen

Option Explicit

Private Sub CommandButton1_Click()

Call ClipboardGetFiles

End Sub

Weitere Infos bie


Viele Grüße


geschrieben von




Beitrag anfügen