
MsgBox "Could not unlock memory location. LpGlobalMemory = lstrcpy (lpGlobalMemory, MyString ) ' Unlock the memory.

LpGlobalMemory = GlobalLock (hGlobalMemory ) ' Copy the string to this global memory. HGlobalMemory = GlobalAlloc (GHND, Len (MyString ) + 1 ) ' Lock the block to get a far pointer ' to this memory. # Else Dim hGlobalMemory As Long Dim hClipMemory As Long Dim lpGlobalMemory As Long #End If Dim X As Long ' Allocate moveable global memory. DataObjectĮnd With # Else #If VBA7 Then Dim hGlobalMemory As LongPtr

# Else 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 CloseClipboard Lib "User32" ( ) As Long Declare Function OpenClipboard Lib "User32" ( ByVal hwnd As Long ) As Long Declare Function Empt圜lipboard 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 #End If #End If Public Const GHND = &H42 Public Const CF_TEXT = 1 Public Const MAXSIZE = 4096 Sub ClipBoard_SetData (MyString As String ) #If Mac Then With New MSForms. #If Mac Then ' ignore # Else #If VBA7 Then Declare PtrSafe Function GlobalUnlock Lib "kernel32" ( ByVal hMem As LongPtr ) As LongPtrĭeclare PtrSafe Function GlobalLock Lib "kernel32" ( ByVal hMem As LongPtr ) As LongPtrĭeclare PtrSafe Function GlobalAlloc Lib "kernel32" ( ByVal wFlags As Long, _ ByVal dwBytes As LongPtr ) As LongPtrĭeclare PtrSafe Function CloseClipboard Lib "User32" ( ) As Long Declare PtrSafe Function OpenClipboard Lib "User32" ( ByVal hwnd As LongPtr ) As LongPtrĭeclare PtrSafe Function Empt圜lipboard Lib "User32" ( ) As Long Declare PtrSafe Function lstrcpy Lib "kernel32" ( ByVal lpString1 As Any, _ ByVal lpString2 As Any ) As LongPtrĭeclare PtrSafe Function SetClipboardData Lib "User32" ( ByVal wFormat _ As Long, ByVal hMem As LongPtr ) As LongPtr
