[AccessD] 64bit and the Clipboard.

Stuart McLachlan stuart at lexacorp.com.pg
Mon Jul 18 01:43:05 CDT 2022


There are a number of VBA functions on the intertubes for getting/setting strings on the 
Clipboard. They use Global memory and memory copies with API functions.  UNfortunately 
none of them seem to work with 64bit Office no matter how you tweak with PtrSafe, LongPtr 
etc.

I finally came across a function that uses a totally different approach that works perfectly in 
my testing. - and it's much simpler too :)
Courtesy of: ExcelHero.com (Daniel Ferry)

I tweaked it a bit to suit my style for the code below :)

( I no longer have a 32bit Office installation, can someone using it try the function and report 
back? )


Function Clipboard(Optional sText As String) As String
'PURPOSE: Set/Get  Clipboard text.  Omitting sText Gets the clipboard text
Dim x As Variant    'variant required for 64bit
Dim oHTMLFile As Object
  x = sText
  Set oHTMLFile = CreateObject("htmlfile")
  With oHTMLFile
    With .parentWindow.clipboardData
      Select Case Len(sText)
        Case 0 'No vriable passed, Read from the clipboard
            Clipboard = .GetData("text")
        Case Else 'Write to the clipboard
            .setData "text", x
      End Select
    End With
  End With
  Set oHTMLFile = Nothing
End Function






More information about the AccessD mailing list