A Microsoft Excel forum. ExcelBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » ExcelBanter forum » Excel Newsgroups » Excel Programming
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Embedding Existing Excel chart into VB6 form



 
 
Thread Tools Display Modes
  #1  
Old April 8th 17, 08:47 PM posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
Ads
  #2  
Old April 8th 17, 09:09 PM
cacuoc334465c cacuoc334465c is offline
Banned
 
First recorded activity by ExcelBanter: Apr 2017
Posts: 20
Default

Quote:
Originally Posted by View Post
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&quot Set wbk = xl.workbooks.open(CurDir & "\LiveChart.xlsx&quot 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
Cảm ơn bạn vì b*i viết rất bổ *ch v* thú vị
  #3  
Old April 8th 17, 09:28 PM posted to microsoft.public.excel.programming
GS[_6_]
external usenet poster
 
Posts: 717
Default 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
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Embedding a pie chart from excel Dig Charts and Charting in Excel 1 December 9th 07 05:26 AM
Embedding an annotation or a comment to a chart in Excel 2007 Refresher Charts and Charting in Excel 5 August 13th 07 08:01 PM
Embedding spreadsheet in a user form GeorgeJ Excel Discussion (Misc queries) 3 July 24th 07 07:20 PM
Can I scan an existing paper form into excel accounting Excel Discussion (Misc queries) 3 January 25th 07 06:13 PM
Embedding excel charts in my C# windows form Matt Kosorok Charts and Charting in Excel 0 May 11th 05 05:02 PM


All times are GMT +1. The time now is 01:19 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright 2004-2017 ExcelBanter.
The comments are property of their posters.