Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting that an Excel file has been changed

Status
Not open for further replies.

SGLong

Programmer
Jun 6, 2000
405
US
I've got a VFP application that builds and/or opens an Excel file. How do I detect if the user has made any changes to the Excel file. If they've made no changes I'd just like to close the file and application, otherwise I'd like to prompt them to "Save" or "Save As".

Steve
 

Steve,

Not sure about this, but I think that if you call the workbook's Close method with the appropriate parameter, it will do what you want automatically. Excel will itself issue the prompt if the workbook has changed; your program won't have to do it.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
I use the following to check for a document, open it if it exists, and process, then close it


*check to see if document exists
If .Not. File("this.doc")

*create new document based on template file
loDoc = loWord.documents.add("this.dot")

*save it immediatly
loDoc.SaveAs("this.doc")

**put additions to document here

*save the document without prompting
lodoc.saveas("this.doc")

*quit word without prompting
loWord.Quit(0)

else

** open the file

*** do processing

** close as above

endif

wjwjr
 
Steve,

Just to follow up my previous reply ...

The Close method takes an optional parameter, which has the following settings:

True
Saves the changes to the workbook. If there is not yet a file name associated with the workbook, then FileName is used. If FileName is omitted, the user is asked to supply a file name.

False
Does not save the changes to this file.

Omitted
Displays a dialog box asking the user whether or not to save changes.

(This is quoted from the VBA Help file).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hi!

In MSWord there i sa property which shows wether or not the doc is 'dirty' (changed).
Maybe some is available in Excel as well?

-Bart
 
I need to know how many rows there are in Sheet 1 of an XL workbook that I have opened. The best function that I have found is :
oExcel.Cells.SpecialCells(11).row

However, if the user has a second sheet in the workbook (in which I am not interested), and he has saved the workbook so that that is the current page, then the above function returns the number of rows on the second page, and I then mistakenly only work on a subset of the rows on sheet 1.

I also notice that if Sheet 2 had been saved as the user’s current sheet, then after my program has finished and populated the cells of sheet 1, when the user opens it using Excel, he still starts on Sheet 2, but can then click on sheet 1 to see all the stuff I have generated.

So my question is “How can I make Sheet 1 the current sheet, so that the SpecialCells(11) function works off that sheet, and so that when the user opens the workbook, that is the sheet he sees”


 

Andrew,

Could I suggest you start a new thread for this question, as it is not really an answer to Steve's original query.

Steve,

Are you still here? We gave you some possible solutions to your question, but didn't here back from you.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

Sorry - I've not had a chance to get back to this project. A really high priority job pushed it to the back burner. I hope to return to it in about 1-2 weeks. I will let everyone know what I came up with.

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top