You are on page 1of 7

Hi,

I am not sure this is the right group for this.


My VFP 9 application runs Excel automation.
In 29 steps, a sheet is formatted in a certain way.
I noticed that some steps take considerably longer time than others,
and I wonder if there's other faster ways to achieve the same goal.

I post the code below.

The most time consuming steps are 17 (columns resizing) and 21 (add
footer and page numbers).
They take twice longer than steps 3, 4, 5, 23.
They take 10 times longer than steps 1, 6, 7, 8, 19, 24, 25, 26, 27,
28.
They take 90 times longer than steps 10, 12, 13, 15, 20, 29.

Fixing somehow steps 17, 21, 3, 4, 5 and 23 would improve speed.


Thank you for help, and sorry in case this is not the right group.

*1
oSheet = .Worksheets.Add()
_VFP.DataToClip(,,3)
oSheet.Paste()
oSheet.Name = "#" + TRIM(vstore)

*2
..Range("A:Z").Font.Size = 8

*3
..ActiveWorkbook.ActiveSheet.Pagesetup.LeftMargin = 36 && era 18
..ActiveWorkbook.ActiveSheet.Pagesetup.RightMargin = 27 && era 18

*4
..ActiveWorkbook.ActiveSheet.Pagesetup.TopMargin = 36
..ActiveWorkbook.ActiveSheet.Pagesetup.BottomMargin = 54

*5
..ActiveWorkbook.ActiveSheet.Pagesetup.HeaderMargin = 18
..ActiveWorkbook.ActiveSheet.Pagesetup.FooterMargin = 18

*6
..range("A:D").delete
*7
..range("J:K").delete

*8
..range("A:A,A1").numberformat = "0"

*9
..range("D:D,D1").numberformat = "0000"

* 10
..range("G:I").numberformat = "#,##0.00"

* 11
..range("A1").value = "UPC"
..range("B1").value = "Style"
..range("C1").value = "Style Desc"
..range("D1").value = "WP Color"
..range("E1").value = "Size"
..range("F1").value = "Qty"
..range("G1").value = "Cost $"
..range("H1").value = "Amount $"
..range("I1").value = "Retail $"
*.range("J1").value = "Diff $"

* 12
..range("A1:I1").Borders.LineStyle = 1

* 13
* Left: -4131, Center = -4108, Right = -4152
..range("F1:J1").HorizontalAlignment = -4108

* 14
..ActiveWorkbook.ActiveSheet.pagesetup.printtitlerows = "$A1:$J1"

* 15
..range("A:A,B:B,D:D,E:E").horizontalalignment = -4131

* 16
..range("J:J,J1").horizontalalignment = -4152

* 17
..Columns("A:A").ColumnWidth = 12 && UPC was 13
..Columns("B:B").ColumnWidth = 15 && Style was 13
..Columns("C:C").ColumnWidth = 16 && Styledesc
..Columns("D:D").ColumnWidth = 7 && Wp color
..Columns("E:E").ColumnWidth = 5 && Size
..Columns("F:F").ColumnWidth = 4 && Qty
..Columns("G:G").ColumnWidth = 7 && Cost was 8
..Columns("H:H").ColumnWidth = 10 && Amount
..Columns("I:I").ColumnWidth = 8 && Retail
..Columns("J:J").ColumnWidth = 6

* 18
totqtycell = "F"+ALLTRIM(STR(storereccount+2))
..range(totqtycell).Select
..range(totqtycell).FormulaR1C1 = "=SUM(R[-"+ALLTRIM(STR(storereccount))
+"]C:R[-1]C)"
..range(totqtycell).Select
..range(totqtycell).font.bold = .T.
..range(totqtycell).font.size = 9

* 19
totamtcell = "H"+ALLTRIM(STR(storereccount+2))
..range(totamtcell).Select
..range(totamtcell).FormulaR1C1 = "=SUM(R[-"+ALLTRIM(STR(storereccount))
+"]C:R[-1]C)"
..range(totamtcell).Select
..range(totamtcell).font.bold = .T.
..range(totamtcell).font.size = 9

* 20
..Range("A1").Select

* 21
..ActiveWorkbook.ActiveSheet.PageSetup.PrintArea = ""
..ActiveWorkbook.ActiveSheet.PageSetup.RightHeader = ""
..ActiveWorkbook.ActiveSheet.PageSetup.LeftFooter = "FLI" + ' ' + dts
..ActiveWorkbook.ActiveSheet.PageSetup.RightFooter = "&P/&N" && es:
1/3

* 22
..selection.entirerow.insert()
..Range("A1").value = COMPNAME
..Range("A1").font.size = 14
..Range("A1").font.bold = .T.
..Range("A2").select

* 23
..selection.entirerow.insert()
..Range("A2").value = v_tpc + SPACE(22-LEN(tpc)) + 'PO #' + v_po
..Range("E2").value = v_dn + v_btl
..Range("A2:E2").font.size = 11
..Range("A2:E2").font.bold = .T.
..Range("A3").select
..selection.entirerow.insert()
..Range("A3:L3").font.size = 9
..Range("A3:L3").font.bold = .F.

* 24
..range("A4").select
..selection.entirerow.insert()
..range("A4").value = v_pod + v_pot + v_vn

* 25
..range("A5").select
..selection.entirerow.insert()
..range("A5").value = v_sh + v_snbd + v_drd + v_dndbd + v_psd + v_cad +
v_dndad + v_cindbd

* 26
IF NOT (v_pgn == '' AND v_an == '' AND v_smop == '')
.range("A6").select
.selection.entirerow.insert()
.range("A6:L6").font.size = 8
.range("A6").value = v_pgn + v_an + v_smop
ENDIF

* 27
IF NOT(v_tt == '' AND v_tbdc == '' AND v_tdp1 == '' AND v_tdp2 == ''
AND v_tdduda == '' ;
AND v_tddadu == '' AND v_tndd =e= '' AND v_tnd == '' AND v_tda == '')
.range("A7").select
.selection.entirerow.insert()
.range("A7:L7").font.size = 8
.range("A7").value = v_tt + v_desc_a + v_tbdc + v_desc_b ;
+ IIF(v_tdp1 == v_tdp2, v_tdp1, v_tdp1 +
v_tdp2) ;
+ v_tdduda + v_tddadu + v_tndd + v_tnd + v_tda
ENDIF

* 28
..Rows(.selection.Row+1).Insert

* 29
..range("J1").select
.

● Follow-Ups​:
○ Re: Excel automation within VFP
■ From:​ Jürgen Wondzinski
○ Re: Excel automation within VFP
■ From:​ Dan Freeman
● Prev by Date:​ ​Re: Dbf does not exist
● Next by Date:​ ​Re: Excel automation within VFP
● Previous by thread:​ ​Dbf does not exist
● Next by thread:​ ​Re: Excel automation within VFP
● Index(es):
○ Date
○ Thread

Relevant Pages
● Re: Update Excel Spreadsheet from
Access VBA
● ...​ Sounds like you need to perform
some ​Excel Automation.​ ​...​ >I want to
read in an ​Excel spreadsheet​, ​...​ I
don't mind treating the whole ​sheet​ as
a table, ​...​ > ​Update method​ doesn't
work and I can't find any other ways
other than ​...
● (microsoft.public.access.devtoolkits)
● Re: Exporting a large table to excel
● ...​ Use ​Excel automation,​ while
slower,​ it'll work in all versions of ​VFP!
...​ ​Rick​ ​...
● (microsoft.public.fox.programmer.exch
ange)
● Re: Append from "Excel File" TYPE
XL8 give 1661 error if file saved from
Excel 2007
● ...​ to ​Excel automation​ and scraping
the data from the ​sheet​ one ​cell​ at ​...
aren't Office2007 files just ​XML?​ ​...
● (microsoft.public.fox.programmer.exch
ange)
● Re: Exporting datagrid to Excel in a
Windows Application
● ...​ or to populate a ​sheet​ using ​Excel
automation.​ ​...​ the ​response object,
e.g. ​...​ How to achieve the same in a
C# ​windows​ application? ​...
● (microsoft.public.dotnet.languages.csh
arp)
● Excel Blues! Automation with VFP 8
● ...​ Whilst rolling out a package
programmed in ​VFP​ 8 and using ​Excel
Automation,​ ​...​ I have come across a
number of cases where the ​creation
of the Excel Object ​...​ routine to ​trap
all such errors - I would like to trap
them and disable the ​...
● (microsoft.public.fox.programmer.exch
ange)

Flag as inappropriate
(18)
● Windows
● Science
● Usenet
● Archive
● About
● Privacy
● Search
● Imprint
​www.tech-archive.net​ > ​Archive​ > ​Fox​ > ​microsoft.public.fox.helpwanted​ > ​2009-12

You might also like