Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Changes To Excel File Not Saving
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
01333224
Message ID:
01333248
Vues:
9
>I had this working and now it's now saving:
>
>
>** Instantiate Excel
>oExcel = CREATEOBJECT("Excel.Application")
>
>** Open the workbook
>oWorkbook = oExcel.Workbooks.Open(sFileName)
>
>** Get a reference to the sheet
>oSheet = oExcel.Workbooks(1).ActiveSheet
>
>** Select all cells
>oSheet.Cells.Select()
>
>** Autofit the cells
>oSheet.Cells.EntireColumn.AutoFit()
>
>** Turn on auto filtering
>IF NOT oSheet.AutoFilterMode
>   oExcel.Selection.AutoFilter
>ENDIF
>			
>** Save the changes
>oWorkbook.Save()
>
>** Close the workbook and quit Excel
>oWorkbook.Close()
>oExcel.Quit()
>
>
>
>When the oWorkbook.Close() line is run, I get prompted to save changes. Anyone know what I did wrong?
>
>Also, how do I unselect the selection in code?

Probably you have other workbook open. Are you sure that changes were not saved?

As of unselect, then:
oExcel.cells(1,1).activate
Other than that, you do not need to make selection. Also I would recommend to avoid using references if you can proceed without them (or at least close them properly prior to closing Excel, otherwise you may have them hidden even after you close the program but they appear as Excel instances in the windows Task MAnager Process list):
oExcel = CREATEOBJECT("Excel.Application")
WITH  oExcel.Workbooks.Open(sFileName)
	WITH .ActiveSheet.usedrange
		.EntireColumn.AutoFit()
		IF NOT .parent.AutoFilterMode
			.AutoFilter
		ENDIF
	ENDWITH
	.Save()
	.Close()
ENDWITH

oExcel.Quit()
Good Luck
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform