PDA

View Full Version : Assistance with PasteSpecial needed please



Mediocre Egg
03-31-2008, 08:16 AM
I have a simple userform created, which takes the inputted information and dumps it into a Word .dot file with bookmarks.

Part of this userform involves dumping a previously taken screenshot into the document. To do this I used PasteSpecial.

Right now I have things set up to ignore an error if nothing is in the clipboard. That is fine with me because at that point the screenshot can easily be added manually.

But I'm having trouble figuring out what to do if there is an object in the clipboard, but it's not a screenshot. For example, if the user last copied a bunch of text, it will dump it into the document.

Is there a way to check that the clipboard file is an image file? If not, can anyone recommend a better way of doing what I'm trying to do?

The Sub in question:

Private Sub cmdSubmit_Click()

On Error Resume Next

With ActiveDocument
.Bookmarks("Reason").Range.Text = cboReason.Value
.Bookmarks("Duration").Range.Text = cboDuration.Value
.Bookmarks("Publication").Range.Text = cboPubName.Value
.Bookmarks("Comments").Range.Text = txtComments.Value
.Bookmarks("Screenshot").Range.PasteSpecial
End With

Application.ScreenUpdating = True

Unload Me

End Sub

fumei
03-31-2008, 11:21 AM
Hmmmmmm.

You could have a checkbox on the userform that they check IF they have a screen dump for use. Not checked, no dump.

You could do a - sort of - testing in reverse.
ActiveDocument.Bookmarks("ScreenShot").Range _
.PasteSpecial , , , , DataType:=4


Look in the Object Browser (put wdPaste in the search box). You will see the constants for the datatype.

4 = wdPasteBitmap

So yes, it would paste with a image if that image was, say, a PrintScreen.

5 = wdPasteDeviceIndepentdentBitmap

would also Paste.

2 = wdPasteText

would fail, error 5342 DataType is unavailable.

So, by defining the datatype that IS pasted, if it succeeds it is a graphic, if it fails, it is not. Therefore, USE the error as part of your logic.

fumei
03-31-2008, 11:24 AM
Note that wdPasteMetafilePicture (3) would probably fail.

Mediocre Egg
03-31-2008, 11:59 AM
Both of those are fantastic suggestions. I didn't consider something so simple as a checkbox or another visual reminder for the form.

And I will look into the dPaste constants to see if I can get it to work that way as well.

Thanks!