document.open

S

Steven

I read somewhere, and I believe it was on the knowledge
base, that there was a danger in using the open method to
open a document from within the same application, and
that a better way of accessing another document while in
Word was to use some other method. The article said that
there was a risk of file corruption or something. Well,
I assumed that such a danger couldn't apply to me (how
naive) so in my Word document template that I was
designing, I referred to another document that contained
a table with data in it. (I wanted to retrieve text from
the various cells of the table and insert them at various
bookmarks in my template.

In a module named NewMacros, I used the documents.open
method. The syntax was as follows:

Set docLegalError = Documents.Open("C:\...path & filename
of document containing table of data")

I then, though automation, grabbed the text out of the
cells that I wanted and inserted the text in my
bookmarks. This worked several times but after about a
dozen uses, I could no longer use my template. Not only
that, I could not use any part of Word that used a
UserForm. It seemed like a .dll or something was
corrupted. I eventuall uninstalled MSOffice and
reinstalled it. My template worked again for a while but
then corrupted again! I uninstalled and reinstalled but
am now afraid to use the template. That is when I
recalled the article warning of the danger of using the
document.open method. I can't find the article and am
not sure if it is referring to my type of situation.

A couple of other points that might be relevant:
When the Document.Open method is used, I can see the
document open while I grab the data through automation.
I thought this would be done invisibly.

After grabbing the data and storing it into an array, I
closed the document as follows:

docLegalError.Close
Set docLegalError = Nothing

I also noticed that my document object that I set (e.g.,
docLegalError) was not declared when I declared my
variables such as Dim docLegalError As Document. Could
that be the problem?

Am I doing something wrong here?
Should I be looking for some bad code in my Userform?
 
C

Charles Kenyon

No comment on your methods. However, are you trying to reinvent AutoText? If
so, why?
--
Charles Kenyon

Word New User FAQ & Web Directory:
<URL: http://www.addbalance.com/word/index.htm>

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide)
<URL: http://www.addbalance.com/usersguide/index.htm>

Word Resources Page
<URL: http://www.addbalance.com/word/wordwebresources.htm>

See also the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
J

Jonathan West

Hi Steven

I've used Documents.Open regularly ever since Word 97 came out. Never had
any trouble with it. Never *heard* of anyone having trouble with it, never
come across any article warning me about it.

I doubt very much that Documents.Open is the source of your problem.

If you want the document not to be visible, use the Visible parameter of the
Open method to make it invisible.

based on what you have described, you are simply openign the document and
closing it again without saving it, so I can't see what would be corrupting
it. Unless you are editing it in some way while it is open.

I'll echo what Charles said - it looks like your are reinventing AutoText.
Take a look at the autotext feature and see if that offers a better
approach.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top