[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Excel Automation

Posted on 2010-11-15
6
Medium Priority
?
1,145 Views
Last Modified: 2012-08-13
I want to add to my excel automation code

1. create minor Horizontal gride lines

2. besides having blue, red, green bars have each color have a pattern inside too. So if printed on blank and white it would stand out wich one wsa which.

3. how can I make the Chart bigger than what it keeps coming out to be?

Thanks
*For Excel Corrections Graph
		lcTitleWC = "Loc: "+lcLoc+" " +lcDept+" IRR Correction for " +lcBeginLastWeek+ " to " +lcEndLastWeek+ "."
		lcCatTitleWC = "Error Codes / Time / Cost"
		lcValTitleWC = " Number of Occurences"
	
* Open Excel Sheet
		oExcel = Createobject("Excel.Application")
		oExcel.Visible = .T.
		oWorkbook = oExcel.Workbooks.Open("c:\irr_corrections_graph_"+ALLT(STR(m.loc))+"_"+m.dept+".xls")

* Format the Font
		oRange = oExcel.ActiveSheet.Range("A1:I1").Select
		oExcel.Selection.Font.Bold = .T.
		oExcel.Selection.Font.Underline = 2
		oRange = oExcel.ActiveSheet.Range("A2:I2").Select
		*oExcel.ActiveWindow.FreezePanes = .T.
		oExcel.ActiveSheet.Cells.Select
		oExcel.ActiveSheet.Cells.EntireColumn.AutoFit

*Size the chart
		oChart = oExcel.Sheets[1].ChartObjects.Add(45.7,173.2,319.5,190.5)
		oChart.Activate
		oRange = 'oExcel.ActiveSheet.Range("A1:A' + cRows + ',B1:B' + cRows + ',C1:C' + cRows + ',D1:D' + cRows + '")'
		oExcel.ActiveChart.ChartWizard(&oRange, 3, 4, 2, 1, 1, .T.,lcTitleWC, lcCatTitleWC, lcValTitleWC)
		*oExcel.ActiveChart.SetElement (msoElementPrimaryValueGridLinesMinorMajor)
		*oExcel.ActiveChart.SeriesCollection[1].HasDataLabels = .T.
		*oExcel.ActiveChart.SeriesCollection[1].ApplyDataLabels[3]
*Turn OFF prompt to overwrite existing file
*Excel Equivalent of 'SET SAFETY OFF'
		oExcel.DisplayAlerts = .F.
* Save and quit Excel
		oWorkbook.SaveAs("c:\irr_corrections_graph_"+ALLT(STR(m.loc))+"_"+m.dept+".xls", xlExcel8)
		*oExcel.Quit

Open in new window

0
Comment
Question by:jaymz69
[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
  • 2
6 Comments
 
LVL 12

Expert Comment

by:jrbbldr
ID: 34141049
For items 1 & 2 do the work manually in Excel while recording your actions as a Macro.  
When done, stop recording the Macro.
Then go into the Macro as if you were going to Edit it and look at the resultant VBA code.

That tells you what to do in VFP Excel automation and, in most cases, how to do it albeit in a different language.

You can try the same for item #3, but not having done it personally myself, I cannot guarantee it will give you what you need.   But it is an excellent place to start.

Good Luck


0
 
LVL 2

Accepted Solution

by:
Gary2Seven earned 2000 total points
ID: 34142880


To add a medium thick border to a range;
(oSheet is set to page you want to work with)

WITH oSheet.RANGE(<Range>)
  WITH .BORDERS(xlEdgeLeft)
    .LineStyle = xlContinuous
    .Weight = xlMedium
    .ColorIndex = xlAutomatic
  ENDWITH
  WITH .BORDERS(xlEdgeRight)
    .LineStyle = xlContinuous
    .Weight = xlMedium
    .ColorIndex = xlAutomatic
  ENDWITH
  WITH .BORDERS(xlEdgeTop)
    .LineStyle = xlContinuous
    .Weight = xlMedium
    .ColorIndex = xlAutomatic
  ENDWITH
  WITH .BORDERS(xlEdgeBottom)
    .LineStyle = xlContinuous
    .Weight = xlMedium
    .ColorIndex = xlAutomatic
  ENDWITH
ENDWITH

Open in new window


to add internal lines use;
WITH oSheet.RANGE(<Range>)
    WITH .BORDERS(xlInsideVertical)
      .LineStyle = xlContinuous
      .Weight = xlThin
      .ColorIndex = xlAutomatic
    ENDWITH

    WITH .BORDERS(xlInsideHorizontal)
      .LineStyle = xlContinuous
      .Weight = xlThin
      .ColorIndex = xlAutomatic
ENDWITH

Open in new window


when you want to fill the cell use;
WITH oSheet.RANGE(<Range>)
  WITH .Interior
    .ColorIndex = 0
    .PATTERN = xlLightUp
    .PatternColorIndex = 40    
  ENDWITH
ENDWITH

Open in new window

I use the colorindex as it is compatable with older versions of Excel, Excel 2010 has a new way of using more colours, but is not compatable with older versions taht most of my clients have.

I've not done any work resizing charts (although I do feed them from data in an Excel workbook, my understanding is that it shows as a chart object and you can access it like a worksheet.

I have attached the #Include file that has most of the xlConstants.


excel9.h.txt
0
 

Author Comment

by:jaymz69
ID: 34145284
I have three types on my Cluster bar Graph will the internal line fill do three different fills for all three types?

Thanks again
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:jaymz69
ID: 34145303
also with that txt do you just point to it at the top of your code?
0
 
LVL 2

Expert Comment

by:Gary2Seven
ID: 34145338

The internal line is for cells, not graphs you can use combinations of line, fill etc to format your work sheet.

You need to rename the .txt file as .h and then add;

#INCLUDE excel9.h

or add it to the forms include file setting in teh IDE.
0
 

Author Comment

by:jaymz69
ID: 34145379
got it.

Thanks
0

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
With the evolution of technology, we have finally reached a point where it is possible to have home automation features like having your thermostat turn up and door lock itself when you leave, as well as a complete home security system. This is a st…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 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