Solved

Create Chart in Excel ' 97 using VB6

Posted on 2000-05-13
3
371 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA color chart bars 12 85
bit defender blocks good applications 2 93
VBA Shell can't Find Word document 11 92
VB6 ListBox Question 4 42
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

775 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