Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2006

Tip: Looking for answers? Try searching our database.

Documents(0) - what is it?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gregor2324@wp.pl - 27 Sep 2006 10:18 GMT
Hi,

I have a problem with my VB app using VBA for Word 97, sometimes it
goes crazy when I
try to localize my document name using Documents(i) when i iterates
from 1 to Documents.Count.

I noticed that usually the object Documents(0) does not exist, but if
it does, my application goes wrong (it can't find my document and so
can't close it, the file is open and I get Permission Denied error when

I try to save it.) These problems exist only when Documents(0) exists
and usually holds the document I can't locate.
In the documentation I read that the first document is however,
Documents(1). Moreover, in that case two names are usually the same!
For example Documents(2).Name = Documents(3).Name is True! What's the
problem?

Thanks in advance.
Tony Jollans - 27 Sep 2006 10:35 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.