WordBasic Macro to Assign Clipboard Text to a String VariableLast reviewed: July 30, 1997Article ID: Q82111 |
The information in this article applies to:
SUMMARYThis function retrieves any text residing on the Clipboard. All formatting is ignored, and the Clipboard content is stored in the variable clipboard$. As with all WordBasic strings, the maximum string size is 32,768 characters or what local memory allows.
MORE INFORMATION
Function to Assign Clipboard Text to a String Variable
Declare Function CloseClipboard Lib "user32"() As Long Declare Function GetClipboardData Lib "user32"(wFormat As Long) As Long Declare Function OpenClipboard Lib "user32"(hwnd As Long) As Long Declare Function GlobalLock Lib "kernel32"(h As Long) As Long Declare Sub GlobalUnlock Lib "kernel32"(h As Long) Declare Function lstrcpyA Lib "kernel32"(lpszDest$, lpsz2 As Long)As Long Declare Function lstrlenA Lib "kernel32"(lpsz As Long) As Long ' ********************************************************************** Sub Mainhwnd = GetFocus If (OpenClipboard(hwnd) <> 0) Then h = GetClipboardData(1) If (h <> 0) Then lpStr = GlobalLock(h) Clip$ = String$(lstrlenA(lpStr), "x") r = lstrcpyA(Clip$, lpStr) Clip$ = LTrim$(RTrim$(Clip$)) GlobalUnlock(h) Else Clip$ = "NULL" End If r = CloseClipboardMsgBox Clip$ End SubThis function can be called from within any subroutine in a macro. It can also reside in a "functions" macro. You can then call this function from within another WordBasic macro. The syntax is as follows:
Within Same Macro
Sub MAINMsgBox Clipboard$ End Sub Within Another Macro
Sub MAINMsgBox Global.Clipboard$ End SubUse the following steps to create the macro:
For information about how to do this in Word 97, please see the following article(s) in the Microsoft Knowledge Base:
ARTICLE-ID: Q158436 TITLE : Sample VB Code to Assign Clipboard Text to String Variable REFERENCES"Microsoft Word for Windows User's Guide," version 2.0, pages 765, 784-786 "Using WordBasic," by WexTech Systems and Microsoft, pages 173, 186 Kbcategory: kbusage kbmacro KBSubcategory: |
Additional query words: 2.0 2.0a 6.0 6.0a 6.0c winword2
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |