Thema Datum  Von Nutzer Rating
Antwort
26.06.2024 14:51:42 Bernd
NotSolved
26.06.2024 16:35:06 ralf_b
NotSolved
26.06.2024 16:59:05 Bernd
NotSolved
26.06.2024 17:51:20 ralf_b
NotSolved
27.06.2024 09:49:09 Bernd
NotSolved
27.06.2024 12:45:41 Gast12307
NotSolved
27.06.2024 13:35:21 ralf_b
NotSolved
27.06.2024 13:35:51 Bernd
NotSolved
27.06.2024 13:53:39 Gast16397
NotSolved
27.06.2024 14:45:30 Bernd
NotSolved
27.06.2024 14:57:06 Gast65894
NotSolved
27.06.2024 15:01:21 Gast11406
NotSolved
27.06.2024 15:04:15 Bernd
NotSolved
27.06.2024 15:14:17 Gast25925
NotSolved
27.06.2024 15:30:45 Bernd
NotSolved
27.06.2024 15:34:43 Gast42945
NotSolved
27.06.2024 15:39:25 Bernd
NotSolved
27.06.2024 15:44:53 Bernd
NotSolved
27.06.2024 15:55:11 Gast12642
NotSolved
27.06.2024 16:32:57 Bernd
NotSolved
28.06.2024 09:01:50 Bernd
NotSolved
27.06.2024 19:40:47 xlKing
NotSolved
28.06.2024 17:36:04 volti
NotSolved
30.06.2024 14:31:51 Bernd
Solved
30.06.2024 15:00:24 Volti
NotSolved
01.07.2024 06:59:45 Bernd
NotSolved
Rot Variable in Zwischenablage funktioniert nicht
01.07.2024 08:50:21 volti
NotSolved
03.07.2024 17:46:44 Bernd
Solved
07.07.2024 19:21:13 Gast7777
NotSolved

Ansicht des Beitrags:
Von:
volti
Datum:
01.07.2024 08:50:21
Views:
88
Rating: Antwort:
  Ja
Thema:
Variable in Zwischenablage funktioniert nicht

Hallo Bernd,

 

das hast Du ja schon gut angepasst.

Der hier gezeigte Code ist für VBA7 für 32Bit und 64Bit Excel geeignet. Für 32Bit Excel VBA6 (älteres Excel) ist er nicht mehr geeignet.

Maßgebend ist hier die Verwendung des Schlüsselwortes PtrSafe und die Verwendung von LongPtr für Handles und Pointer.

LongPtr für 32 und 64 Bit. Hat man nur eine 64Bit-Anwendung kann auch der Variablentyp Longlong verwendet werden.

Was passiert dort: Habe ein paar Kommentare dazugeschrieben.

 

Code:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 
' (c) 01.07.2024 Volti, Freigericht
' ###############  In ein allgemeines Modul #############
Private Declare PtrSafe Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, _
        ByVal dwBytes As LongPtrAs LongPtr
Private Declare PtrSafe Function GlobalLock Lib "kernel32" (ByVal hMem As LongPtrAs LongPtr
Private Declare PtrSafe Function GlobalUnlock Lib "kernel32" (ByVal hMem As LongPtrAs Long
Private Declare PtrSafe Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, _
        ByVal lpString2 As AnyAs LongPtr
Private Declare PtrSafe Function SetClipboardData Lib "user32" (ByVal wFormat As Long, _
        ByVal hMem As LongPtrAs LongPtr
Private Declare PtrSafe Function OpenClipboard Lib "user32" (ByVal hWnd As LongPtrAs Long
Private Declare PtrSafe Function CloseClipboard Lib "user32" () As Long
Private Declare PtrSafe Function EmptyClipboard Lib "user32" () As Long

Function KopiereinClpbrd(Optional ClpTxt As StringAs String
' Kopieren über die API
  Dim hMem As LongPtr, lpGMem As LongPtr

  hMem = GlobalAlloc(&H42Len(ClpTxt) + 1)      ' Speicher reservieren &H42=GMEM_MOVEABLE + GMEM_ZEROINIT
  lpGMem = GlobalLock(hMem)                      ' Speicherbereich blocken                  
  lpGMem = lstrcpy(lpGMem, ClpTxt)               ' Text in Speicher übertragen
  If GlobalUnlock(hMem) = 0 Then                 ' Speicherbereich unblocken
     If OpenClipboard(0&) <> 0 Then              ' Zwischenablage öffnen
        EmptyClipboard                           ' Zwischenablage leeren
        SetClipboardData 1, hMem   ' 1=CF_TEXT     Daten dort rein 
        CloseClipboard                           ' Zwischenablage schließen
     End If
  End If
End Function


' ############### In irgendein Modul #############
Sub Copytest()

  ' Vorheriger Makroteil

  Dim EQNR As String

  EQNR = "12345678"     ' kommt im Makro aus vorherigem Makroteil

  KopiereinClpbrd EQNR

' Nachvolgender Makroteil

End Sub
_________
viele Grüße
Karl-Heinz

Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
26.06.2024 14:51:42 Bernd
NotSolved
26.06.2024 16:35:06 ralf_b
NotSolved
26.06.2024 16:59:05 Bernd
NotSolved
26.06.2024 17:51:20 ralf_b
NotSolved
27.06.2024 09:49:09 Bernd
NotSolved
27.06.2024 12:45:41 Gast12307
NotSolved
27.06.2024 13:35:21 ralf_b
NotSolved
27.06.2024 13:35:51 Bernd
NotSolved
27.06.2024 13:53:39 Gast16397
NotSolved
27.06.2024 14:45:30 Bernd
NotSolved
27.06.2024 14:57:06 Gast65894
NotSolved
27.06.2024 15:01:21 Gast11406
NotSolved
27.06.2024 15:04:15 Bernd
NotSolved
27.06.2024 15:14:17 Gast25925
NotSolved
27.06.2024 15:30:45 Bernd
NotSolved
27.06.2024 15:34:43 Gast42945
NotSolved
27.06.2024 15:39:25 Bernd
NotSolved
27.06.2024 15:44:53 Bernd
NotSolved
27.06.2024 15:55:11 Gast12642
NotSolved
27.06.2024 16:32:57 Bernd
NotSolved
28.06.2024 09:01:50 Bernd
NotSolved
27.06.2024 19:40:47 xlKing
NotSolved
28.06.2024 17:36:04 volti
NotSolved
30.06.2024 14:31:51 Bernd
Solved
30.06.2024 15:00:24 Volti
NotSolved
01.07.2024 06:59:45 Bernd
NotSolved
Rot Variable in Zwischenablage funktioniert nicht
01.07.2024 08:50:21 volti
NotSolved
03.07.2024 17:46:44 Bernd
Solved
07.07.2024 19:21:13 Gast7777
NotSolved