Documents(0) should never exist and, even if it did, iterating from 1 to
Documents.Count would never stumble across it.
Can you be a bit more precise in stating what your problem is, what the
error is, in what code, and under what circumstances it occurs. What makes
you think you have a documents(0)?
Secondly, Documents(2).Name = Documents(3).Name can be true if the two
documents are in different folders - use FullName or Path to differentiate
them.
--
Enjoy,
Tony
> Hi,
>
[quoted text clipped - 15 lines]
>
> Thanks in advance.
gregor2324@wp.pl - 27 Sep 2006 11:23 GMT
Tony Jollans napisal(a):
> Documents(0) should never exist and, even if it did, iterating from 1 to
> Documents.Count would never stumble across it.
[quoted text clipped - 30 lines]
> >
> > Thanks in advance.
Here's my code
.....................
'I 've created a new document under new name Document4
set docs = mobjWord1.Documents
'Now I check if Word has opened the old document
For Each doc In docs
If doc.Name = offer.oname + ".doc" Then
doc.Close ' this never executes
End If
Next
strFileName = "c:\offers\files\" & offer.oname & ".doc"
If Len(Dir(strFileName)) Then
If MsgBox("Overwrite existing offer?", vbYesNo) = vbYes Then
Kill strFileName ' this causes Permission Denied (the file
is blocked by Word)
Now a look in the Immediate Window shows the following:
? offer.oname
Geschaft
? docs.Count
2
? docs(0).Name
Geschaft.doc
? docs(1).Name
Document4
? docs(2).Name
Document4
Tony Jollans - 27 Sep 2006 18:52 GMT
Hi, Gregor,
A partial explanation (perhaps): unless you have "Option Compare Text"
specified, comparisons in VBA will be case-sensitive, so if your document is
called geschaft.doc it would not be closed but it would be found by Dir.
The Documents(0) is very odd. Where are you running this code from that you
have an object reference to the Word application?
--
Enjoy,
Tony
> Tony Jollans napisal(a):
> > Documents(0) should never exist and, even if it did, iterating from 1 to
[quoted text clipped - 60 lines]
> ? docs(2).Name
> Document4