Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. articles. downloads. faq. members. files. rss.
 From: anton
  Where is anton?
 san juan
 Philippines
 anton
 To: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
Subject: RE: vfp to excel codes for multi worksheet
Thread ID: 168829 Message ID: 169533 # Views: 6 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Microsoft Office Automation
Date: Thursday, April 24, 2008 6:40:25 PM         
   



> >
> > Cetin,
> >
> > the truth is... my codes are awful and i dont like it.. hehehe.. dont worry sir im not offended with your reactions coz that was expected and i know how to handle criticism coz thats where i grow..
> >
> > I appreciate an expert like you sharing knowledge to us newbies.. thats truly unselfish of you.. for that i idolize you..
> >
> > My deepest thanks for the tips and advices.. more power...
> >
> > oh by the way sir.. do you know a site or a reference regarding macro translation to vfp?...
> >
> > Anton
>
> This is what I could find from 2002 (didn't check earlier). Pasting the message as is:
> -------------------------------------------------------------------------------------------
>
> >I have a problem trying to translate a VBA statement into the VFP equivalent to manage an automation requirement. - any suggestione would be most welcome:
> >
> >**Code below is the VB for Applications syntax
> >
> >**Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(2), _
> >** Replace:=True, PageBreaks:=False, SummaryBelowData:=True
>
> Sam,
> I think this is macro recording. Macro recording uses VBA syntax with 'named parameters'. VFP uses 'positional parameters'. With named parameters style you could supply the parameters in 'any order' by assigning names to them as in your sample. Fortunately from Excel97 and up help gives the syntax with their correct 'positions'. Suntotal syntax reads :
>
> expression.Subtotal(GroupBy, Function, TotalList, Replace, PageBreaks, SummaryBelowData)
>
> With this syntax your call would translates to VFP :
> * Step 1 - fill the values with their names to corect positions
>
> Selection.Subtotal(GroupBy:=1, Function:=xlSum, TotalList:=Array(2), ;
> Replace:=True, PageBreaks:=False, SummaryBelowData:=True)
>
> * Step 2 - Remove unwanted parameter names and convert things like true/false
> * to VFP counterpat
>
> Selection.Subtotal(1, xlSum, Array(2), .T., .F., .T.)
>
> * Step 3 - Array(2) is a VBA function, supply VFP counterpart
> dimension arrFlds[1]
> arrFlds[1]=2
>
> Selection.Subtotal(1, xlSum, @arrFlds, .T., .F., .T.)
>
> * Step 4 - Omit optional params that are already at their defaults
> * xlSummaryBelow is a constant with value 1 and therefore .t./.f.
> * would work. However it's better to use value there. In this case
> * xlSummaryBelow is default and optional, will omit
> * First 3 are 'required' params
>
> Selection.Subtotal(1, xlSum, @arrFlds, .T.)
>
> * Note : If say we'd omit 3rd parameter and keep 4th
> * function would look like
> * SomeFunction(Par1, Par2, ,Par4)
>
> * Step 5 - Be sure what this function applies to and use it VFP style
>
> Selection.Subtotal(1, xlSum, @arrFlds, .T.)
> * Would fail since no Selection object exists
> * Assuming excel.application is oExcel and we're in a with..endwith
> * pointing to an object of oExcel
> * ie: with oExcel.Activeworkbook.ActiveSheet
> * Subtotal applies to 'Range' and 'WorkSheetFunction'
> * 'Selection' is a 'range' object but always keep in mind
> * 'selection' is a member of oExcel itself.
> * oExcel.Selection would work but here we're at a deeper level
> * (oExcel.Activeworkbook.ActiveSheet). At any level .Application
> * points to oExcel itself. So we'd say :
>
> .Application.Selection.Subtotal(1, xlSum, @arrFlds, .T.)
>
> Below code demonstrates this with another shortcut 'range' object :
>
>
> #Define xlSum -4157
> #Define xlSummaryAbove 0
> #Define xlSummaryBelow 1
> #Define xlSummaryOnLeft -4131
> #Define xlSummaryOnRight -4152
>
> Select *, quantity*unit_price as 'extended' ;
> from orditems into cursor crsTemp
> lcXLS = sys(5)+curdir()+'xlsubtot.xls'
> Copy to (lcXLS) type xls
> Dimension totflds[2] && This is our offsets array
> totflds[1]=5 && We want Quantity and Extended to be totalled - 5,6th positions
> totflds[2]=6
> oX = createobject('Excel.Application')
> With oX
> .Workbooks.Open(lcXLS)
> *!* with .ActiveWorkbook.ActiveSheet
> *!* .UsedRange.Select
> *!* .Application.Selection.Subtotal(2, xlSum, @totflds, .T.)
> *!* endwith
> .ActiveWorkbook.ActiveSheet.UsedRange.Subtotal(2, xlSum, @totflds, .T.)
> .visible = .t.
> Endwith
> Cetin
> -------------------------------------------------------------------------------------------
> Cetin Basoz

Cetin,

hi! how are you?.. thanks for a speedy response.. you truly are a guru.... a rating is not enough for your kindness and unselfishness.... but hey dont ask money coz i dont have any.. hahaha..

this will be a great help indeed.. and i will study this...

thank you so much sir...

Anton

ENTIRE THREAD

vfp to excel codes for multi worksheet Posted by anton d @ 4/21/2008 6:19:29 AM
RE: excel automation Posted by Lyrad Bangoy @ 4/21/2008 7:45:17 AM
RE: excel automation Posted by Samir Ibrahim @ 4/21/2008 10:25:29 AM
RE: vfp to excel codes for multi worksheet Posted by Ken Murphy @ 4/21/2008 5:51:23 PM
RE: vfp to excel codes for multi worksheet Posted by anton d @ 4/21/2008 7:34:46 PM
RE: vfp to excel codes for multi worksheet Posted by Ken Murphy @ 4/21/2008 8:54:15 PM
RE: vfp to excel codes for multi worksheet Posted by anton d @ 4/22/2008 12:59:32 AM
RE: vfp to excel codes for multi worksheet Posted by Lyrad Bangoy @ 4/22/2008 8:05:45 AM
RE: vfp to excel codes for multi worksheet Posted by anton d @ 4/27/2008 4:31:22 AM
RE: vfp to excel codes for multi worksheet Posted by Ken Murphy @ 4/27/2008 2:43:56 PM
RE: vfp to excel codes for multi worksheet Posted by Anders Altberg @ 4/21/2008 6:21:09 PM
RE: vfp to excel codes for multi worksheet Posted by anton d @ 4/21/2008 7:36:53 PM
RE: vfp to excel codes for multi worksheet Posted by Cetin Basoz @ 4/22/2008 12:00:49 PM
RE: vfp to excel codes for multi worksheet Posted by Samir Ibrahim @ 4/22/2008 4:27:31 PM
RE: vfp to excel codes for multi worksheet Posted by Cetin Basoz @ 4/22/2008 10:41:45 PM
RE: vfp to excel codes for multi worksheet Posted by Samir Ibrahim @ 4/24/2008 9:44:07 AM
RE: vfp to excel codes for multi worksheet Posted by anton d @ 4/22/2008 11:10:08 PM
RE: vfp to excel codes for multi worksheet Posted by Cetin Basoz @ 4/24/2008 12:00:15 AM
RE: vfp to excel codes for multi worksheet Posted by anton d @ 4/24/2008 4:00:24 PM
RE: vfp to excel codes for multi worksheet Posted by Ken Murphy @ 4/24/2008 4:24:49 PM
RE: vfp to excel codes for multi worksheet Posted by anton d @ 4/24/2008 5:51:48 PM
RE: vfp to excel codes for multi worksheet Posted by Cetin Basoz @ 4/24/2008 5:55:15 PM
RE: vfp to excel codes for multi worksheet Posted by Cetin Basoz @ 4/24/2008 6:04:08 PM
RE: vfp to excel codes for multi worksheet Posted by anton d @ 4/24/2008 6:40:25 PM
RE: vfp to excel codes for multi worksheet Posted by Ken Murphy @ 4/24/2008 6:43:37 PM
RE: vfp to excel codes for multi worksheet Posted by Cetin Basoz @ 4/24/2008 7:44:47 PM
RE: vfp to excel codes for multi worksheet Posted by anton d @ 4/26/2008 6:19:07 PM
RE: vfp to excel codes for multi worksheet Posted by Cetin Basoz @ 4/26/2008 10:05:33 PM
RE: vfp to excel codes for multi worksheet Posted by anton d @ 4/27/2008 5:09:06 AM
RE: vfp to excel codes for multi worksheet Posted by Anders Altberg @ 4/22/2008 12:15:32 PM
RE: vfp to excel codes for multi worksheet Posted by Cetin Basoz @ 4/22/2008 10:47:17 PM
RE: vfp to excel codes for multi worksheet Posted by Anders Altberg @ 4/22/2008 11:44:05 PM
RE: vfp to excel codes for multi worksheet Posted by Cetin Basoz @ 4/23/2008 1:03:57 AM
RE: vfp to excel codes for multi worksheet Posted by Anders Altberg @ 4/23/2008 5:49:08 PM
RE: vfp to excel codes for multi worksheet Posted by anton d @ 4/22/2008 11:12:57 PM
RE: vfp to excel codes for multi worksheet Posted by Anders Altberg @ 4/23/2008 5:19:59 PM
RE: vfp to excel codes for multi worksheet Posted by anton d @ 4/24/2008 4:10:43 PM
RE: vfp to excel codes for multi worksheet Posted by anton d @ 4/26/2008 7:17:47 PM
RE: vfp to excel codes for multi worksheet Posted by Christian Bonafos @ 4/23/2008 9:13:38 AM
RE: vfp to excel codes for multi worksheet Posted by Anders Altberg @ 4/23/2008 6:08:15 PM
RE: vfp to excel codes for multi worksheet Posted by Christian Bonafos @ 4/24/2008 5:57:13 PM
RE: vfp to excel codes for multi worksheet Posted by anton d @ 4/24/2008 7:01:38 PM