Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Create Chart in Excel ' 97 using VB6

Posted on 2000-05-13
3
Medium Priority
?
413 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 143

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 300 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

824 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