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
good
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 (PastePicture.zip 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
'' http://www.oaltd.co.uk/Excel/Default.htm
'' 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). _
ChartObjects(1).Chart
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"
Else
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


Regards,
Peter T


.



Relevant Pages

  • Re: insert an Excel graph into a Richtextbox?
    ... Via the clipboard is also the only way to get an image of an Excel Chart, ... The long established "Excel chart to clipboard to picture object" is Stephen ... If bBMP Then ...
    (microsoft.public.vb.general.discussion)
  • Re: insert an Excel graph into a Richtextbox?
    ... actually create a single metafile representing the entire chart which it ... Excel could "put us wise" on the matter. ... contents of the clipboard so that they were the same after the operation as ... Static bBMP As Boolean ...
    (microsoft.public.vb.general.discussion)
  • Re: Update "buildin" excel in a powerpoint with macro
    ... tried to run the macro manualy with the tool>macro>run updategraph. ... make a simple chart in an Excel workbook ... Switch to a new empty PowerPoint presentation ... Switch back to Excel and quit Excel ...
    (microsoft.public.mac.office.powerpoint)
  • Re: Update "buildin" excel in a powerpoint with macro
    ... Problem #2 - How to get the macro to run more than a single time. ... make a simple chart in an Excel workbook ... Switch to a new empty PowerPoint presentation ... Switch back to Excel and quit Excel ...
    (microsoft.public.mac.office.powerpoint)
  • Re: Update "buildin" excel in a powerpoint with macro
    ... make a simple chart in an Excel workbook ... Edit Paste (to paste the chart into PowerPoint) ... Switch back to Excel and quit Excel ... ' Loop through each slide in the presentation. ...
    (microsoft.public.mac.office.powerpoint)