Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the Union Method of excel automation

Status
Not open for further replies.

ravicoder

Programmer
Apr 29, 2006
30
IN
Hi all

I am using excel automation extensively in my project for reporting

My query is:

I have a sheet with data on it -different types of data in different columns

I want to generate different charts based on particular sets of data for which I need to select any 2 or more non-adjacent columns for the data range. VBA code gives me the Union() method to achieve this. How to do I use this or similar in visual foxpro?

Any Help or guidance/sample code would be greatly appreciated

Thanks
Ravi Bangera
 
Methods of objects are available to these objects, no matter if you write code in VBA or VFP.

If UNION(...) is not a method of an object but a pure VBA function, then the simplest solution to use it is to write a VBA macro and call that from VFP with something like oExcel.Run("MacroName")

Chriss
 
Ravi,

I have never used the VBA Union function, but a glance at the VBA Help tells us what we need to know.

You say you use Excel Automation extensively, so I assume you know how to get a worksheeet object and how to define ranges.

The Union function is a member of the application object. It takes two or more ranges, and combines them into a single range. In this case, the ranges would be the columns that contain the data for your charts. So, your VFP code might look something like this:

Code:
loFirstCol = loSheet.Range("A1:A10")
loSecondCol = loSheet.Range("B1:B10")
loBothCols = loExcel.Union(loFirstCol, loSecondCol)

You would then pass loBothCols to your charts in the usual way.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top