Clipboard.clear 
Author Message
 Clipboard.clear

I'm trying to set a macro in Word 97 to clear the clipboard before copying
some info with an ole function.  I found in VB 5 you can use
clipboard.clear, but when I try that in VBA, it says it needs an object.  I
tried to dim the clipboard as an object, but no luck.... Thanks!



Fri, 04 Aug 2000 03:00:00 GMT  
 Clipboard.clear

Hope This Will Help (Also how you know about API's):

Public Const GHND = &H42
Public Const MAXSIZE = 4096
Public Const CF_TEXT = 1
Private Const CF_ANSIONLY = &H400&
Private Const CF_APPLY = &H200&
Private Const CF_BITMAP = 2
Private Const CF_DIB = 8
Private Const CF_DIF = 5
Private Const CF_DSPBITMAP = &H82
Private Const CF_DSPENHMETAFILE = &H8E
Private Const CF_DSPMETAFILEPICT = &H83
Private Const CF_DSPTEXT = &H81
Private Const CF_EFFECTS = &H100&
Private Const CF_ENABLEHOOK = &H8&
Private Const CF_ENABLETEMPLATE = &H10&
Private Const CF_ENABLETEMPLATEHANDLE = &H20&
Private Const CF_ENHMETAFILE = 14
Private Const CF_FIXEDPITCHONLY = &H4000&
Private Const CF_FORCEFONTEXIST = &H10000
Private Const CF_GDIOBJFIRST = &H300
Private Const CF_GDIOBJLAST = &H3FF
Private Const CF_HDROP = 15
Private Const CF_INITTOLOGFONTSTRUCT = &H40&
Private Const CF_LIMITSIZE = &H2000&
Private Const CF_LOCALE = 16
Private Const CF_MAX = 17
Private Const CF_METAFILEPICT = 3
Private Const CF_NOFACESEL = &H80000
Private Const CF_NOSCRIPTSEL = &H800000
Private Const CF_NOSIMULATIONS = &H1000&
Private Const CF_NOSIZESEL = &H200000
Private Const CF_NOSTYLESEL = &H100000
Private Const CF_NOVECTORFONTS = &H800&
Private Const CF_NOOEMFONTS = CF_NOVECTORFONTS
Private Const CF_NOVERTFONTS = &H1000000
Private Const CF_OEMTEXT = 7
Private Const CF_OWNERDISPLAY = &H80
Private Const CF_PALETTE = 9
Private Const CF_PENDATA = 10
Private Const CF_PRINTERFONTS = &H2
Private Const CF_PRIVATEFIRST = &H200
Private Const CF_PRIVATELAST = &H2FF
Private Const CF_RIFF = 11
Private Const CF_SCALABLEONLY = &H20000
Private Const CF_SCREENFONTS = &H1
Private Const CF_BOTH = (CF_SCREENFONTS Or CF_PRINTERFONTS)
Private Const CF_SCRIPTSONLY = CF_ANSIONLY
Private Const CF_SELECTSCRIPT = &H400000
Private Const CF_SHOWHELP = &H4&
Private Const CF_SYLK = 4
Private Const CF_TIFF = 6
Private Const CF_TTONLY = &H40000
Private Const CF_UNICODETEXT = 13
Private Const CF_USESTYLE = &H80&
Private Const CF_WAVE = 12
Private Const CF_WYSIWYG = &H8000
Private Declare Function GlobalAlloc Lib "kernel32" _
    (ByVal wFlags&, ByVal dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" _
    (ByVal hMem As Long) As Long
Private Declare Function GlobalSize Lib "kernel32" _
    (ByVal hMem As Long) As Long
Private Declare Function lstrcpy Lib "kernel32" _
    (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
Private Declare Function GlobalUnlock 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 GetClipboardData Lib "User32" _
    (ByVal wFormat As Long) 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
Function ClipBoard_SetData(MyString As String)
    Dim hGlobalMemory As Long, lpGlobalMemory As Long
    Dim hClipMemory As Long, X As Long
    ' Allocate moveable global memory.
  '-------------------------------------------
  hGlobalMemory = GlobalAlloc(GHND, Len(MyString) + 1)
  ' Lock the block to get a far pointer
  ' to this memory.
  lpGlobalMemory = GlobalLock(hGlobalMemory)
  ' Copy the string to this global memory.
  lpGlobalMemory = lstrcpy(lpGlobalMemory, MyString)
  ' Unlock the memory.
    If GlobalUnlock(hGlobalMemory) <> 0 Then
    MsgBox "Could not unlock memory location. Copy aborted."
    GoTo OutOfHere2
    End If
  ' Open the Clipboard to copy data to.
    If OpenClipboard(0&) = 0 Then
    MsgBox "Could not open the Clipboard. Copy aborted."
    Exit Function
    End If
  ' Clear the Clipboard.
  X = EmptyClipboard()
  ' Copy the data to the Clipboard.
  hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)
OutOfHere2:
If CloseClipboard() = 0 Then
MsgBox "Could not close Clipboard."
End If
End Function
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
  ' Obtain the handle to the global memory
  ' block that is referencing the text.
  hClipMemory = GetClipboardData(CF_TEXT)
  If IsNull(hClipMemory) Then
    MsgBox "Could not allocate memory"
    GoTo OutOfHere
  End If
  ' Lock Clipboard memory so we can reference
  ' the actual data string.
  lpClipMemory = GlobalLock(hClipMemory)
  If Not IsNull(lpClipMemory) Then
    MyString = Space$(MAXSIZE)
    Retval = lstrcpy(MyString, lpClipMemory)
    Retval = GlobalUnlock(hClipMemory)
    ' Peel off the null terminating character.
    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

--
\                                           /
  \   Brian Mailloux              /

/                                          \

Quote:

>I'm trying to set a macro in Word 97 to clear the clipboard before copying
>some info with an ole function.  I found in VB 5 you can use
>clipboard.clear, but when I try that in VBA, it says it needs an object.  I
>tried to dim the clipboard as an object, but no luck.... Thanks!



Sun, 06 Aug 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Clipboard.Clear - Returns Error 424 - Object Required

2. Newbie question: clipboard.clear

3. Clipboard.clear doesn't work!!

4. CLIPBOARD.CLEAR doesn't work.

5. Access XP: Clearing the clipboard / not saving data to the clipboard

6. Clearing the clipboard/memory

7. Clear the clipboard

8. Clearing the clipboard from Access

9. Clear Clipboard

10. clear clipboard

11. Clearing the Clipboard

12. Clear Clipboard on file.close

 

 
Powered by phpBB® Forum Software