Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to read latest clipboard entry from VBA?

Posted on 2006-06-15
5
Medium Priority
?
663 Views
Last Modified: 2011-10-03
I need to read the latest Windows clipboard entry to a VBA string variable.  How is that done?
0
Comment
Question by:liberty1947
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 16917907
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 252 total points
ID: 16917930
I had some simple API calls somewhere, that link above is not that helpful
I cant find it sorry
so try this from MS instead

http://support.microsoft.com/?kbid=210213

0
 
LVL 15

Assisted Solution

by:cquinn
cquinn earned 248 total points
ID: 16918947
Option Compare Database
Option Explicit

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 EmptyClipboard 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
Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Declare Function GlobalSize Lib "KERNEL32" (ByVal hMem As Long) As Long
Public Const GHND = &H42
Public Const CF_TEXT = 1
Public Const MAXSIZE = 4096

Public Function ClipBoard_GetData()

         Dim hClipMemory As Long
         Dim lpClipMemory As Long
         Dim MyString As String
         Dim RetVal As Long

         If OpenClipboard(0&) = 0 Then
            MsgBox "Cannot open Clipboard. Another app. may have it open"
            Exit Function
         End If
         hClipMemory = GetClipboardData(CF_TEXT)
         If IsNull(hClipMemory) Then
            MsgBox "Could not allocate memory"
            GoTo OutOfHere
         End If

         lpClipMemory = GlobalLock(hClipMemory)

         If Not IsNull(lpClipMemory) Then
            MyString = Space$(MAXSIZE)
            RetVal = lstrcpy(MyString, lpClipMemory)
            RetVal = GlobalUnlock(hClipMemory)


            MyString = Mid(MyString, 1, InStr(1, MyString, Chr$(0), 0) - 1)
         Else
            MsgBox "Could not lock memory to copy string from."
         End If

OutOfHere:

         RetVal = CloseClipboard()
         ClipBoard_GetData = MyString

End Function

Public Function ClipBoard_SetData(MyString As String)

         Dim hGlobalMemory As Long, lpGlobalMemory As Long
         Dim hClipMemory As Long, x As Long

         hGlobalMemory = GlobalAlloc(GHND, Len(MyString) + 1)
         lpGlobalMemory = GlobalLock(hGlobalMemory)


         lpGlobalMemory = lstrcpy(lpGlobalMemory, MyString)


         If GlobalUnlock(hGlobalMemory) <> 0 Then
            MsgBox "Could not unlock memory location. Copy aborted."
            GoTo OutOfHere2
         End If


         If OpenClipboard(0&) = 0 Then
            MsgBox "Could not open the Clipboard. Copy aborted."
            Exit Function
         End If


         x = EmptyClipboard()


         hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)

OutOfHere2:

         If CloseClipboard() = 0 Then
            MsgBox "Could not close Clipboard."
         End If

End Function
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question