Re: insert an Excel graph into a Richtextbox?

"Karl E. Peterson" wrote in message
Bob O`Bob wrote:

I am not in any way objecting to the clipboard,
that was a *suggestion*

It's been years since I had to work with a RTB but, as I recall, the only
way to
insert a graphic is indeed from the clipboard. That'd make this a pretty
suggestion, if so. <g>

Via the clipboard is also the only way to get an image of an Excel Chart, at
least AFAIK other than Excel's export-chart method to file (eg as a gif).

The long established "Excel chart to clipboard to picture object" is Stephen
Bullen's PastePicture.xls example ( from the link in
comments below). I notice your name, Karl, is listed in the credits!

FWIW a quick VB6 example

'' Requires all the code as-is from Stephen Bullen's
'' modPastePicture in PastePicture.xls in a normal module
'' with these constants included (if late binding)

'Public Const xlPicture As Long = -4147
'Public Const xlScreen As Long = 1
'Public Const xlBitmap As Long = 2

' in a Form with a Button, an Image and/or PictureBox

Private moCht As Object

Private Sub Command1_Click()
Dim lPicType As Long
Static bBMP As Boolean ' to compare picture types

On Error Resume Next
If moCht Is Nothing Then
'assumes an embedded chart exists on the first sheet
'of the active workbook in a running instance of Excel
Set moCht = GetObject(, "excel.application"). _
ActiveWorkbook.Worksheets(1). _
End If

If moCht Is Nothing Then
MsgBox Err.Description
Exit Sub
End If
On Error GoTo 0

If bBMP Then
lPicType = xlPicture
Me.Caption = "xlPicture"
lPicType = xlBitmap
Me.Caption = "xlBitmap"
End If
bBMP = Not bBMP

' manually: with selected chart, Shift-Edit / Copy Picture
moCht.CopyPicture xlScreen, lPicType, xlScreen

Image1.Stretch = True
Set Image1.Picture = PastePicture(lPicType)

Picture1.AutoSize = True
Set Picture1.Picture = PastePicture(lPicType)

End Sub

Thinking aloud, when an Excel embedded chart is selected it appears in it's
own window (there can only ever be one chart window). I wouldn't know how to
go about it but maybe it's possible to get its image without using the
clipboard. If anyone is so inclined ? :-) maybe this might help as a starter

' if not 100% sure there's only one Excel instance
' need to replace vbNullstring with xlApp.Caption (only in the first call)
hWindXL = FindWindow("XLMAIN", vbNullString)

hWndWB = FindWindowEx(hWindXL, 0, "XLDESK", vbNullString)
hWndChart = FindWindowEx(hWndWB, 0, "EXCELE", vbNullString)
' If hWndChart = 0 ensure an embedded chart is selected

hDcChart = GetDC(hWndChart)

' ?

ReleaseDC hWndChart, hDcChart

Peter T