Solved

Create Chart in Excel ' 97 using VB6

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

744 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

11 Experts available now in Live!

Get 1:1 Help Now