There is no need to save changes as all files are information read only files.
This code fails what's wrong?
Public Sub Closeallworkbooks()
Dim Wkb As Workbook
For Each Wkb In Workbooks
If Wkb.Name <> ThisWorkbook.Name Then
Wkb.Saved = True
Wkb.Close
End If
Next Wkb
With ThisWorkbook
.Saved = True
.Close
End With
End Sub
Public Sub Closealldocs()
Dim oDoc As Document
For Each oDoc In Documents
If oDoc.Name <> ThisDocument.Name Then
oDoc.Saved = True
oDoc.Close
End If
Next oDoc
With ThisDocument
.Saved = True
.Close
End With
End Sub
Private Sub Document_Close()
Stop
Call Closeallworkbooks
Call Closealldocs
End Sub
> The code I posted will work from Word. Your code will also, if you qualify
> the object references. The code for Word is similar, but you iterate the
[quoted text clipped - 59 lines]
> >> > Thanks in anticipation
> >> > Colt
If you're trying to run that in Word, it's because you haven't qualified the
object references -- you have to tell VBA that these objects belong to the
Excel application object, which you have to instantiate. Have a look at the
code I posted.
Separately, there's no need to handle ThisWorkbook and ThisDocument
separately from the other workbooks and documents. In fact, if you're
running from Word, I'm not sure that ThisWorkbook will be valid at all,
since that's a reference to the workbook that contains the running code.
> There is no need to save changes as all files are information read only
> files.
[quoted text clipped - 107 lines]
>> >> > Thanks in anticipation
>> >> > Colt
colt - 25 Aug 2006 07:34 GMT
Sorry for not responding quickly - had to get my extensions maths group a
lesson thanks for all your help I much appreciate it. I'll have a go with the
code you suggested. thanks again
colt
> If you're trying to run that in Word, it's because you haven't qualified the
> object references -- you have to tell VBA that these objects belong to the
[quoted text clipped - 117 lines]
> >> >> > Thanks in anticipation
> >> >> > Colt