How to copy to clipboard using Access/VBA?

前端 未结 3 932
故里飘歌
故里飘歌 2020-11-27 03:59

Using VBA inside Access2003/2007.

How to copy the contents of a string variable to the clipboard?

This site recommends a creating a zero length TextBox, copy

3条回答
  •  借酒劲吻你
    2020-11-27 04:09

    User Leigh Webber on the social.msdn.microsoft.com site posted VBA code implementing an easy-to-use clipboard interface that uses the Windows API:

    http://social.msdn.microsoft.com/Forums/en/worddev/thread/ee9e0d28-0f1e-467f-8d1d-1a86b2db2878

    You can get Leigh Webber's source code here

    If this link doesn't go through, search for "A clipboard object for VBA" in the Office Dev Center > Microsoft Office for Developers Forums > Word for Developers section.

    I created the two classes, ran his test cases, and it worked perfectly inside Outlook 2007 SP3 32-bit VBA under Windows 7 64-bit. It will most likely work for Access. Tip: To rename classes, select the class in the VBA 'Project' window, then click 'View' on the menu bar and click 'Properties Window' (or just hit F4).

    With his classes, this is what it takes to copy to/from the clipboard:

    Dim myClipboard As New vbaClipboard  ' Create clipboard
    
    ' Copy text to clipboard as ClipboardFormat TEXT (CF_TEXT)    
    myClipboard.SetClipboardText "Text to put in clipboard", "CF_TEXT"    
    
    ' Retrieve clipboard text in CF_TEXT format (CF_TEXT = 1)
    mytxt = myClipboard.GetClipboardText(1)
    

    He also provides other functions for manipulating the clipboard.

    It also overcomes 32KB MSForms_DataObject.SetText limitation - the main reason why SetText often fails. However, bear in mind that, unfortunatelly, I haven't found a reference on Microsoft recognizing this limitation.

    -Jim

提交回复
热议问题