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
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