Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Old April 8th 17, 08:47 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Apr 2017
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

  #2   Report Post  
Old April 8th 17, 09:09 PM
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   Report Post  
Old April 8th 17, 09:28 PM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Apr 2015
Posts: 763
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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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 06: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 07: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 06:58 AM.

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

About Us

"It's about Microsoft Excel"

 

Copyright © 2017