how can I save a workbook only if it has been modified?
I'm not sure what to do about the Saved property. Try this
Private Sub Workbook_Open()
ThisWorkbook.Saved = True
End Sub
Here are some more ideas:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
For Each Workbook In Workbooks
Select Case Workbook.Name
Case Is = ThisWorkbook.Name, "TempTest2.xls"
If Not Workbook.Saved Then GoTo SaveAll
Case Else
'ignore if not
End Select
Next
Application.EnableEvents = False 'if you have before save / close code in
others
On Error Resume Next 'in case TempTest2.xls is not open
Workbooks("TempTest2.xls").Close ' savechanges:=false - there should be no
changes, but..
On Error GoTo 0
Application.EnableEvents = True
Exit Sub
SaveAll:
Application.EnableEvents = False 'if you have before save / close code in
others
Workbooks("Book1.xls").Close savechanges:=True
ThisWorkbook.Save
Application.EnableEvents = True
MsgBox ("Saved")
End Sub
Ken Valenti
Quote:
> thanks for your reply, but i think my situation is made slightly more
> difficult, because i've got three workbooks which need saving and the
> operation can happen from any workbook, but the order of saving must be
> the same. I've used your suggestion and also used workbook
> ("a").activate then used activeworkbook.saved for each book, but the
> command always shows FALSE and so it always does a save!
> raj
> Sent via Deja.com http://www.deja.com/
> Before you buy.