Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check Clipboard populated 1

Status
Not open for further replies.

DBAssam

Programmer
Feb 8, 2002
19
0
0
GB
I'm passing data from another app into Word 2000 and autorunning a macro. I keep having to put delays in the macro to ensure that the macro does not run before the clipboard has data.

Q: Does anyone know a way in VBA to check to see if any data is present in clipboard? That way I can put a loop in until there is. I alway flush the clipboard first so either there is data, or it hasn't arrived, which makes it easier hopefully.

Please help!
 
DBAssam,

I have not tested the following but it may work for you. It uses the Win32 API.


Code:
' Predefined Clipboard Formats
Public Const CF_TEXT = 1
Public Const CF_BITMAP = 2
Public Const CF_METAFILEPICT = 3
Public Const CF_SYLK = 4
Public Const CF_DIF = 5
Public Const CF_TIFF = 6
Public Const CF_OEMTEXT = 7
Public Const CF_DIB = 8
Public Const CF_PALETTE = 9
Public Const CF_PENDATA = 10
Public Const CF_RIFF = 11
Public Const CF_WAVE = 12
Public Const CF_UNICODETEXT = 13
Public Const CF_ENHMETAFILE = 14

Public Const CF_OWNERDISPLAY = &H80
Public Const CF_DSPTEXT = &H81
Public Const CF_DSPBITMAP = &H82
Public Const CF_DSPMETAFILEPICT = &H83
Public Const CF_DSPENHMETAFILE = &H8E

Private Declare Function IsClipboardFormatAvailable _
    Lib "user32"(ByVal uFormat As Long) As Long

Inside your sub use something like the following:

Code:
Do While Not CBool(IsClipboardFormatAvailable(FormatConstant))

Loop

p.s. There is more info on this at (look midway through the article).

HTH
M. Smith
 
Not sure if this'll work within what you're trying to do but this checks the clipboard (within an app) also

Sub ClipboardChecker()
If Application.CutCopyMode = 1 Then
MsgBox "Clipboard Populated"
Else
MsgBox "Nothing On Clipboard"
End If
End Sub
HTH
~Geoff~
[noevil]
 
Geoff,

FYI -- I tested your suggestion, since it would certainly be much simpler to implement, but it does not seem to work.

I placed some text onto the Clipboard from another app then read the CutCopyMode property from Excel and it registered 0. [sadeyes]

Regards,
Mike
 
Yeh - had a feeling that'd be the case - hence my 1st line on the previous post - shame, 'cos it works nicely within excel - must be a difference between how the app reads the clipboard and how windows does.
cheers for the update anyway
Rgds
Geoff HTH
~Geoff~
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top