FYI: Prevent clipboard confirm dialog on Office 2003 when closing Word application

J

Jon Sullivan

I have seen a lot of questions asking how to clear the Microsoft Office
clipboard. Although it is not possible to clear it entirely
programatically AFAIK, this method will prevent the dialog asking you
if you want to save the large amount of info on the clipboard when
automating Word. This is useful when you are automating larger
documents ones with images.

Example for Word 2003:

Declare Function EmptyClipboard Lib "user32" () As Long

Sub ClearClipboard24Times()
On Error Resume Next

Dim oNewDoc As Document
Set oNewDoc = Application.Documents.Add

Dim rSpace As Range
Set rSpace = oNewDoc.Range

Dim i As Long
For i = 0 To 12
InsertCharAtDocEnd "0", rSpace
InsertCharAtDocEnd "1", rSpace
Next

oNewDoc.Saved = True
oNewDoc.Close wdDoNotSaveChanges

EmptyClipboard

End Sub

Function InsertCharAtDocEnd(strChar As String, ByRef rSpace As Range)
rSpace.Collapse wdCollapseEnd
rSpace.InsertAfter strChar
rSpace.Copy
End Function

===============================================

Jon Sullivan
Senior Developer
Mindflash Technologies, Inc.
http://www.mindflash.com
 
T

Tony Jollans

I agree that it is not possible to clear the Office Clipboard
programmatically in Word 2002 or 2003.

The dialog asking about 'a large amount of data on the clipboard' refers to
the Windows Clipboard, not the Office Clipboard, and there is no need for
such a complicated process to clear that.

Also, as the Office clipboard is a shared resource it is pretty poor form to
clear it on exit from Word if there are any other Office applications still
running. I suppose one could make a case for it if an entirely automated
process had filled it up but, in that case, it would have been polite to
have saved the original contents - if only I knew how :) - and it might be
better if such a process didn't affect the Office clipboard at all (although
I accept that is difficult, if not impossible, in many circumstances).

Incidentally, there are 24 slots on the Office 2003 Clipboard so, if you
really want to do this, you should loop 24 times.. In Office 2000 there are
just 12 - but in Office 2000 it is easier to work with.
 
Top