Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Excel active rows
Message
 
À
23/05/2003 05:34:58
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Divers
Thread ID:
00792018
Message ID:
00792475
Vues:
21
Thanks Cetin

Always happy to stand corrected. I have struggled to understand how to use the various objects, etc in Excel (and other office products) so your code has really helped.

In the case I was working on I am the creator of the extract file which is really just a transit file for importing into the users accounting system. So except in cases where the end user opened and modified the spreadsheet
'.ActiveSheet.UsedRange.Rows.Count' would suffice. Still, better to be safe than sorry. It does however raise the issue of whether one should carry on after one has detected user modification. Ho hum!!!

Do you know how to delete x number of rows starting at row y.
lcExportFile=GETFILE()
oExcel = CREATEOBJECT([Excel.Application])
WITH oExcel
    *!* Open the workbook
    .Workbooks.Open(lcExportFile)
    .Rows.Delete()			&& Delete the rows
    .Application.Goto(.Worksheets("Sheet1").Range("A1"),.T.)
ENDWITH
Works for my needs at the moment but it does seem a bit brutal.

Thanks again
Geoff Scott

>>Sorry folks, I might have put you wrong there. It appears that
>>
>>
>>oExcel = CREATEOBJECT([Excel.Application])
>>WITH oExcel
>>    .Workbooks.Open(GETFILE())
>>    ?.Worksheets("Sheet1").UsedRange.Rows.Count
>>* or
>>    ?.ActiveSheet.UsedRange.Rows.Count
>>    .Workbooks.Close()
>>ENDWITH
>>oExcel=.F.
>>
>>Returns the number of rows used in the sheet.
>>
>>Regards
>>Geoff
>Snip...
>
>Geoff,
>At first look UsedRange.Rows.Count is the answer but it's NOT.
>UsedRange returns info about 'Used' cells in a sheet. If your sheet has some columns and/or rows left empty at start then what you get is not what you should get to find first available unused row. Suppose someone has customer.xls generated from customer table but user moved the data to start at say M80 and saved. If customer.dbf had 92 rows and 10 columns, UsedRange.Rows.Count and USedRange.Columns.Count would still return 92 and 10 not 80+92, M+10. Hard to describe :) To see what I mean create a test customer.xls, open manually and move the data to start from another row/col instead of A1, save, quit and run (assuming saved in current folder) :
>
>#Define xlA1  1
>#Define xlLastCell  11
>
>lcXLS = Sys(5)+Curdir()+'customer.xls'
>oExcel = Createobject('Excel.application')
>oExcel.Workbooks.Open(lcXLS)
>With oExcel.Activeworkbook.ActiveSheet
>  lcLastCell = .Range("A1").SpecialCells(xlLastCell).Address(.F.,.F.,xlA1)
>  ? 'Last Cell',lcLastCell
>  With .UsedRange
>    ? 'Used Range Address',.Address(.F.,.F.,xlA1)
>    ? 'Used Range Rows',.Rows.Count, 'Cols', .Columns.Count
>  Endwith
>  lcFirstUnusedRowCol = "A"+;
>     Transform(Int(Val(Chrtran(;
>       lcLastCell,Chrtran(lcLastCell,'0123456789',''),''))+1))
>  ? 'First Column at First unused row',lcFirstUnusedRowCol
>  .Range(lcFirstUnusedRowCol).Activate
>Endwith
>oExcel.Visible = .T.
>
Cetin
May all your weeds be wildflowers
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform