Embedding Existing Excel chart into VB6 form
This is a code for vb6 programmers
--------------------------------- Dim xl, wbk Private Sub Command1_Click() Set ThisChart = wbk.sheets(1).ChartObjects(1).Chart fName = CurDir & "\LiveChart.GIF" ThisChart.Export FileName:=fName, FilterName:="gif" Picture1.Picture = LoadPicture(fName) End Sub Private Sub Form_Load() Set xl = CreateObject("Excel.application") Set wbk = xl.workbooks.open(CurDir & "\LiveChart.xlsx") End Sub Private Sub Form_Unload(Cancel As Integer) On Error Resume Next xl.displayalerts = False wbk.save wbk.Close Set xl = Nothing End Sub |
Quote:
|
Embedding Existing Excel chart into VB6 form
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next xl.displayalerts = False wbk.save wbk.Close Set xl = Nothing End Sub You'll find this more efficient... Private Sub Form_Unload(Cancel As Integer) On Error Resume Next xl.wbk.Close False '//no changes so don't save xl.Quit: Set wbk = Nothing: Set xl = Nothing End Sub ...because it cleans up VB6 properly AND doesn't leave Excel running with DisplayAlerts turned off! (Closing a workbook and specifying the SaveChanges arg effectively cancels the "Do you want to save..." alert!) -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
All times are GMT +1. The time now is 03:24 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com