Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
I cannot close Excel.application
Message
From
14/05/2002 14:41:40
 
 
To
14/05/2002 14:31:36
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00656380
Message ID:
00656390
Views:
22
Helen, here is a faster solution than populating Excel one cell at a time:
LOCAL nRows, nMaxRows, lDataToClip
lDataToClip = .F.

IF NOT DBUSED('tastrade')
  OPEN DATABASE _SAMPLES + "tastrade\data\tastrade" SHARED
ENDIF

SELECT * FROM tastrade!customer INTO CURSOR ccust
nRows = RECCOUNT() + 1 && include the header

*-- Open Excel
oExcel = CREATEOBJECT("Excel.Application")
WITH oExcel
  *-- Open the reusable Excel template file
  .WorkBooks.Open('d:\dev\lexnet\excel_tmp.xls')
  *-- How many rows can be written to Excel?
  nMaxRows = .ActiveWorkBook.Activesheet.Rows.Count
  IF nRows < nMaxRows AND nRows <> 1
    .Sheets("Sheet2").Select()
    .Range("A2").Select()
    SELECT ccust
    IF lDataToClip
      *-- create a tab delimited list to the clipboard
      _VFP.DataToClip(,,3)
    ELSE
      *-- This method does not include header info
      FileToStr_ClipText()
    ENDIF
    *-- Paste the data to Excel begining at cell "A2" of "Sheet2"
    .ActiveSheet.Paste()
    *-- Clear out the clipboard
    _ClipText = ""
    *-- Excel's version of SET SAFETY
    .DisplayAlerts = .F.
    *-- Save the file as a new name to keep template in tact.
    .ActiveWorkBook.SaveAs("d:\dev\lexnet\newsheet.xls")
  ENDIF
  *-- Quit Excel
  .Quit()
ENDWITH

PROCEDURE FileToStr_ClipText()
  lcFile = SYS(2015)+".TXT"
  COPY TO (lcFile) DELIMITED WITH TAB
  _Cliptext = FILETOSTR(lcFile)
  ERASE (lcFile)
ENDPROC
>I need to send my DBFs to Excel spredasheet with full functionality. I use the same procedure. All but one work fine. This particular procedure sends 17000 records to Spreadsheet with 12 columns.
>
>loExcel=CREATEOBJECT("Excel.Application")
>WITH loExcel
> .Workbooks.ADD
> .RANGE("A1").VALUE="Date:"
> ..........................
> .RANGE("L1").VALUE="...."
> lnRow=2
> SELECT TEMPRPT
> SCAN
> .Cells(lnRow,1).VALUE=TEMPRPT.Field1
> ....................................
> .Cells(lnRow,12).VALUE=TEMPRPT.Field12
> lnRow=lnRow+1
> ENDSCAN
>ENDWITH
>loExcel.ActiveWorkbook.SaveAs(cName)
>loExcel.ActiveWorkbook.Close
>loExcel.Application.Quit
>loExcel.Quit
>loExcel=.NULL.
>RELEASE loExcel
>
>After executing of this procedure my XLS file is Ok, but EXCEL still open.
>I tried it on Windows 98 and Windows ME. I have VFP5 and Office 2000.
>I have only about 1700 records, but I need to create 12 columns in Excel spreadsheet. I think my problem relates somehow to the columns number, because when I tested my program and eliminated Columns numbet to 8, it worked perfect for the same amount of records. However, when I added 9th column, I got the same problem again.
>I can see my open Excel in Task Meneger, and if I would like to continue, it freezes up my computer.
>
>What's wrong?
>Thanks,
>Helen
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform