Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. sponsors. rss.
 From: Anders Altberg
  Where is Anders Altberg?
 Uppsala
 Sweden
 Anders Altberg
 To: Elijah Kihuga
  Where is Elijah Kihuga?
 Nairobi
 Kenya
 Elijah Kihuga
 Tags
Subject: RE: Save, SaveAs in Excel
Thread ID: 232066 Message ID: 232071 # Views: 21 # Ratings: 0
Version: Visual FoxPro 6 Category: Microsoft Office Automation
Date: Friday, June 19, 2009 12:32:39 PM         
   


> goingtothetop
>
> I am using the code below - different cursors - to copy data from Foxpro to an excel sheet- different columns.
>
> Problem is... I have to click on Save changes... every time I paste and close the workbook.
>
> If I say oExcelObject...Save or SaveAs... it requires overwriting of the main document... which is not required.
>
> Is there a better way forward ?
>
> SELECT Y1Lot
> _VFP.DataToClip()
>
> WITH oExcelObject.Worksheets("Valuations")
> oExcelObject.ActiveSheet.range("A5").select && Paste the Data
> oExcelObject.ActiveSheet.Paste() && Paste the Data
> oExcelWorkbook.close
> ENDWITH
>
> SELECT Y1Valu
> _VFP.DataToClip()
>
> oExcelWorkbook = oExcelObject.Application.Workbooks.Open(cSheet)
>
> WITH oExcelObject.Worksheets("Valuations")
> oExcelObject.ActiveSheet.range("B5").select && Paste the Data
> oExcelObject.ActiveSheet.Paste() && Paste the Data
> oExcelWorkbook.close
> ENDWITH

As a side coment, may I point out that you're using the WITH - ENDWITH the wrong way.

WITH oExcelObject.ActiveSheet && or With oExcelObject.Workbook  or WITH oExcelObject.ActiveWorkBook
  .Range ('A5')
  .Paste() 
  oExcelWorkbook.Close 
ENDWITH 


looks better to me if oExcelObject refers to the Excel Application object. ActiveSheet is an object property of WorkBook.
The point of a WITH block is not to have to repeat the object reference explicitely.

-Anders



COMPLETE THREAD
Save, SaveAs in Excel Posted by Elijah Kihuga @ 6/19/2009 12:15:02 PM
RE: Save, SaveAs in Excel Posted by tushar @ 6/19/2009 12:28:23 PM
RE: Save, SaveAs in Excel Posted by Anders Altberg @ 6/19/2009 12:32:39 PM
RE: Save, SaveAs in Excel Posted by Tamar Granor @ 6/19/2009 10:44:20 PM
RE: Save, SaveAs in Excel Posted by Elijah Kihuga @ 6/20/2009 2:03:10 PM