Hi
The clipboard is the only way, and your problem is easy to solve.
First read the contents of the clipboard and store this data in av variable.
Then copy your image to the clipboard and paste it to the document.
Then restore the contents of the clipboard from the variable.
I have two routines which I use:
First declare variables module-wide
Private clpPict As Picture 'Image from Clipboard
Private clpText As String 'Text from Clipboard
Private clpType As Integer 'Type of data in Clipboard
Sub SaveClip()
If Clipboard.GetFormat(vbCFText) Then
clpType = 1 'Text
clpText = Clipboard.GetText()
Exit Sub
End If
If Clipboard.GetFormat(vbCFBitmap) Then
Set clpPict = Clipboard.GetData(vbCFBitmap)
clpType = 2 'Image
Exit Sub
End If
If Clipboard.GetFormat(vbCFMetafile) Then
Set clpPict = Clipboard.GetData(vbCFMetafile)
clpType = 2 'Image
Exit Sub
End If
If Clipboard.GetFormat(vbCFDIB) Then
Set clpPict = Clipboard.GetData(vbCFDIB)
clpType = 2 'Image
Exit Sub
End If
If Clipboard.GetFormat(vbCFPalette) Then
Set clpPict = Clipboard.GetData(vbCFPalette)
clpType = 2 'Image
Exit Sub
End If
end sub
Private Sub GetClip(ByVal clipType As Integer)
'Restore Clipboard data
Select Case clipType
Case 1 'Text
Clipboard.SetText (clpText)
Case 2
Clipboard.SetData clpPict
Case Else
Clipboard.Clear
End Select
End Sub
Regards
--
Peter Karlström
Midrange AB
Sweden
Post by Jonathan Westtext in the document
if there is some important data is copied by user on clipboard than it will
be replace by image. therefore copy on clipboard is not userfull.
is there any other method to do the same?
Post by Jonathan WestPost by vj5but its going wrong when there is some text which is alraedy copied than it
will overwrite that text with image. how to solve this?
Do you mean text in the clipboard or text in the document?
--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org