Solved

Create Chart in Excel ' 97 using VB6

Posted on 2000-05-13
3
390 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studio 2005 text editor 10 57
Need Nag Screen for Reboot if system up time is over 14 days 12 99
Problem to line 23 81
VBA: loop recent folder and copy txt file. 8 56
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

710 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