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?
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?