Hallo Stefan
Post by Stefan HeinrichsWenn ich in Access Zeilen aus einer Tabelle oder Abfrage (in die
Zwischenablage) kopiere, kopiert Access stets auch die
Spalten-Überschriftenzeile mit. Da ich die kopierten Zeilen direkt in SAP
einfügen möchte, ist die Überschriftenzeile sehr störend.
Wie kann ich es ausschalten, daß Access stets auch die Überschrift kopiert?
Scheib' eine Funktion mir der Du die erste Zeile des Clipboard rauslöschst.
Rufe diese z.B. über einen Buttonclick oder über eine Autokeys Makro auf und
kopiere danach die Daten ins SAP.
Hier, wie so eine Funktion aussehen könnte:
Public Function Clipboard_StripHeader()
Dim strCB As String
Dim I As Long
strCB = ClipBoard_GetData()
I = InStr(strCB, vbCrLf)
If I < Len(strCB) Then
ClipBoard_SetData (Mid(strCB, I + 2))
Else
MsgBox ("Keine Headerzeile gefunden")
End If
End Function
Diese benötigt zwei Funktionen aus der KB:
http://support.microsoft.com/?kbid=210216
http://support.microsoft.com/?kbid=210213
Hier einfachheitshalber alles zusammengefasst zum Einfügen in ein neues
leeres Standard Modul. Verwendung:
- Zeilen in Tabelle/Abfrage in Zwischenablage kopieren
- Funktion Clipboard_StripHeader() aufrufen
- Zwischenablage in Zielumgebung einfügen
'code follows here
Option Compare Database
Option Explicit
Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) _
As Long
Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) _
As Long
Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, _
ByVal dwBytes As Long) As Long
Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) _
As Long
Declare Function CloseClipboard Lib "User32" () As Long
Declare Function OpenClipboard Lib "User32" (ByVal hwnd As Long) _
As Long
Declare Function EmptyClipboard Lib "User32" () As Long
Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, _
ByVal lpString2 As Any) As Long
Declare Function SetClipboardData Lib "User32" (ByVal wFormat _
As Long, ByVal hMem As Long) As Long
Declare Function GetClipboardData Lib "User32" (ByVal wFormat As _
Long) As Long
Public Const GHND = &H42
Public Const CF_TEXT = 1
Public Const MAXSIZE = 4096
' contains code from Microsoft that may be copyrighted
' source:
' - http://support.microsoft.com/?kbid=210216
' - http://support.microsoft.com/?kbid=210213
Function ClipBoard_SetData(MyString As String)
Dim hGlobalMemory As Long, lpGlobalMemory As Long
Dim hClipMemory As Long, X As Long
hGlobalMemory = GlobalAlloc(GHND, Len(MyString) + 1)
lpGlobalMemory = GlobalLock(hGlobalMemory)
lpGlobalMemory = lstrcpy(lpGlobalMemory, MyString)
If GlobalUnlock(hGlobalMemory) <> 0 Then
MsgBox "Could not unlock memory location. Copy aborted."
GoTo OutOfHere2
End If
If OpenClipboard(0&) = 0 Then
MsgBox "Could not open the Clipboard. Copy aborted."
Exit Function
End If
X = EmptyClipboard()
hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)
OutOfHere2:
If CloseClipboard() = 0 Then
MsgBox "Could not close Clipboard."
End If
End Function
Function ClipBoard_GetData()
Dim hClipMemory As Long
Dim lpClipMemory As Long
Dim MyString As String
Dim RetVal As Long
If OpenClipboard(0&) = 0 Then
MsgBox "Zwischenablage kann nicht geöffnet werden, " _
& "eventuell durch andere Anwendung geöffnet."
Exit Function
End If
hClipMemory = GetClipboardData(CF_TEXT)
If IsNull(hClipMemory) Then
MsgBox "Speicher konnte nicht zugewiesen werden"
GoTo OutOfHere
End If
lpClipMemory = GlobalLock(hClipMemory)
If Not IsNull(lpClipMemory) Then
MyString = Space$(MAXSIZE)
RetVal = lstrcpy(MyString, lpClipMemory)
RetVal = GlobalUnlock(hClipMemory)
MyString = Mid(MyString, 1, InStr(1, MyString, Chr$(0), 0) - 1)
Else
MsgBox "Speicher, aus dem Zeichenfolge kopiert werden soll, konnte" _
& "nicht gesperrt werden."
End If
OutOfHere:
RetVal = CloseClipboard()
ClipBoard_GetData = MyString
End Function
Public Function Clipboard_StripHeader()
Dim strCB As String
Dim I As Long
strCB = ClipBoard_GetData()
I = InStr(strCB, vbCrLf)
If I < Len(strCB) Then
ClipBoard_SetData (Mid(strCB, I + 2))
Else
MsgBox "Keine Headerzeile gefunden"
End If
End Function
'end of code snipplet
HTH
Henry
--
Microsoft MVP Office Access
Keine E-Mails auf Postings in NGs. Danke.
Access FAQ www.donkarl.com