Pasting Pictures - Data Format problem

S

Steve

I need to paste (using VBA) pictures into a 2-cell table in a Word document.

Sometimes the pictures are photos copied from the web and they have to be
pasted as Device Independent Bitmaps
(DataType:=wdPasteDeviceIndependentBitmap).

Sometimes they are grouped PowerPoint objects or pictures of Excel graphs
and are pasted in as plain Picture (DataType:=wdPasteMetafilePicture).

I'm using a poor hack (On Error Resume Next) to paste the picture with the
correct data format (see code below). What's the right way to check the data
type on the clipboard before pasting it in? I presume this requires an API
call.

Steve

With oCell1.Range ' top cell in the table
' How to figure out in advance which pic format to use?
On Error Resume Next
.PasteSpecial Link:=False, _
DataType:=wdPasteDeviceIndependentBitmap, _
Placement:=wdInLine, _
DisplayAsIcon:=False

.PasteSpecial Link:=False, _
DataType:=wdPasteMetafilePicture, _
Placement:=wdInLine, _
DisplayAsIcon:=False

.ParagraphFormat.KeepWithNext = True
End With
 
L

Lars-Eric Gisslén

Steve,

You could start with this code and see if it helps you.

'------------------------------------
Const CF_BITMAP = 2
Const CF_DIB = 8
Const CF_ENHMETAFILE = 14
Const CF_METAFILEPICT = 3
Const CF_OEMTEXT = 7
Const CF_TEXT = 1
Const CF_UNICODETEXT = 13
Declare Function IsClipboardFormatAvailable Lib "user32" _
(ByVal nFormat As Long) As Boolean

Sub ClipBoardData()

If IsClipboardFormatAvailable(CF_TEXT) Then
MsgBox "Text data found in the ClipBoard"
ElseIf IsClipboardFormatAvailable(CF_BITMAP) Then
MsgBox "Bitmap data found in the ClipBoard"
ElseIf IsClipboardFormatAvailable(CF_METAFILEPICT) Then
MsgBox "Metafile data found in the ClipBoard"
ElseIf IsClipboardFormatAvailable(CF_ENHMETAFILE) Then
MsgBox "Enhanced Metafile data found in the ClipBoard"
ElseIf IsClipboardFormatAvailable(CF_DIB) Then
MsgBox "Device Independent Bitmap data found in the ClipBoard"
ElseIf IsClipboardFormatAvailable(CF_OEMTEXT) Then
MsgBox "OEM Text data found in the ClipBoard"
ElseIf IsClipboardFormatAvailable(CF_UNICODETEXT) Then
MsgBox "Unicode Text data found in the ClipBoard"
Else
MsgBox "The Clipboard is propably empty or contains unknown data"
End If

End Sub
'------------------------------------

Regards,
Lars-Eric Gisslén
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top