Solved

Create Chart in Excel ' 97 using VB6

Posted on 2000-05-13
3
365 Views
Last Modified: 2010-05-02
How can I create a Chart in excel  using VB? Particularly, i hope to know how to :
1. set its chart type to Bar and line ( co-exist on the same chart );
2. set the color of the bar and line in the chart ;
2. how to tell the chart object from where it should get it's data from in order to chart them.

Can anyone give a some sample codes on the above question?
Thanks you very much.
Desperately need help!!

sunburnt
0
Comment
Question by:sunburnt
3 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2807236
'I assume that appExcel is defined aso...

--------------------------------
  Dim c As Excel.Chart  
On Error GoTo Err
  Set c = appExcel.Charts.Add

REM (3): define data location
  c.SetSourceData Source:=Sheets("Sheet1").Range("A2:B6")
REM (  
 
Err:
  c.Delete
  Set c = Nothing
--------------------------------

For all the rest details, i think the best you can do (because you will have other details to find out) is to do the work once manually, letting the Macro Recorder of Excel generate the code.
from this code you can extract what you really need.

Hope this helps

0
 
LVL 12

Expert Comment

by:mark2150
ID: 2807550
While how you're doing it will work, you can get good results just by using the .Line command on a form or a picturebox. You can draw lines, bars, grids, change colors, etc. and generally tweak your chart to what you want instead of what Excel will allow. This also opens your app up to users that don't have Excel installed - you can run without. Finally it keeps your app from being crippled by someone making a config change to excel or by M$ tweaking the commands.

With a little additional effort you can make the same subroutine render on both the screen for preview and the printer. All you rally have to do is pass the target object to the routine. If you pass a form or a picturebox, you get onscreen display. If you pass the Printer object, you get hard copy with full fidelity. You'll have to put a little conditional logic around the occassional statement in the sub because not all commands are valid on both types of objects (you can't .Cls or set the .Background color on the printer and you can't .EndDoc a form/picturebox) but other than that 95% of your code will be in common. Use the .Scale command to make the units convienient for your data and have at it! It's not that hard and I really don't like requiring an external software application for *MY* code to run.

M
0
 
LVL 1

Accepted Solution

by:
csameer1 earned 100 total points
ID: 2836019
Just record a macro while creating a chart.

It will generate thje code.Later you can modify these to do whatever you want.

At work i use excel a lot for hardware testing ,plotting temps/volts/amps all at the same time
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now