Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Const CF_TEXT = 1
Const GMEM_MOVEABLE = &H2
Const GMEM_ZEROINIT = &H40
Const GHND = &H42
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal
dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalSize 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 EmptyClipboard Lib "USER32" () As Long
Private Declare Function SetClipboardData Lib "USER32" (ByVal wFormat As Long, ByVal
hMem As Long) As Long
Private Declare Function GetClipboardData Lib "USER32" (ByVal wFormat As Long) As Long
Private Declare Sub CopyMemoryLS Lib "Kernel32.dll" Alias "RtlMoveMemory" (ByVal dest
As Any, ByVal src As Any, ByVal n As Long)
'********** END WINDOWS CLIPBOARD DECLARATIONS **********
Function ClipBoard_SetText(strCopyString As String) As Boolean
Dim hGlobalMemory As Long, lpGlobalMemory As Long, hClipMemory As Long
' Allocate moveable global memory
hGlobalMemory = GlobalAlloc(GHND, Len(strCopyString) + 1)
' Lock block to get far pointer to this memory
lpGlobalMemory = GlobalLock(hGlobalMemory)
' Copy the string to global memory
CopyMemoryLS lpGlobalMemory, strCopyString, Len(strCopyString)
' Unlock memory then copy to clipboard
If GlobalUnlock(hGlobalMemory) = 0 Then
If OpenClipboard(0&) <> 0 Then
'If OpenClipboard(Screen.ActiveForm.Hwnd) <> 0 Then 'can't use when debugging
Call EmptyClipboard
hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)
ClipBoard_SetText = CBool(CloseClipboard)
End If
End If
End Function
Function ClipBoard_GetText() As String
Dim hClipMemory As Long, lpClipMemory As Long, strCBText As String
Dim RetVal As Long, lngSize As Long
If OpenClipboard(0&) <> 0 Then
'If OpenClipboard(Screen.ActiveForm.Hwnd) <> 0 Then 'can't use when debugging
'Get handle to global memory block that is referencing the text
hClipMemory = GetClipboardData(CF_TEXT)
If hClipMemory <> 0 Then
'Lock Clipboard memory so we can reference the actual data string
lpClipMemory = GlobalLock(hClipMemory)
If lpClipMemory <> 0 Then
lngSize = GlobalSize(lpClipMemory) 'size of string in
clipboard
strCBText = Space$(lngSize) 'make VBA string to hold
clipboard data
CopyMemoryLS strCBText, lpClipMemory, lngSize 'copy from clipboard to
our string
RetVal = GlobalUnlock(hClipMemory) 'unlock the memory
'Remove the null terminating character
strCBText = Left(strCBText, InStr(1, strCBText, Chr$(0), 0) - 1)
Else
MsgBox "Could not lock memory to copy string from."
End If
End If
Call CloseClipboard 'close the clipboard
End If
ClipBoard_GetText = strCBText
End Function