Word corrupts variables on networked PCs

L

Larry Wallis

Hi All

This was to be an email to Microsoft, but as I have a
corporate license version of Office, I apparently can't
ask them! So here goes...

I have a really odd problem with Word 2000 VBA that I have
posted to various other expert forums for a solution with,
so far, no success.

I have written some code in Word VBA and it works fine on
4 computers, but fails on 5. I have run the code dozens of
times in many variations and it never fails on the 4
working ones, but fails in different ways on the "fails".

All faults appear to be related to the way Word stores
variables using the construction:

ActiveDocument.Variables.Add name:="xxx", Value:=yyy

I have four such variables.

I have embedded the code in a template. One method of
installing my code on a machine is to put the template in
the Templates folder. In Word I click on the template to
open it. If I now close Word it crashes and I get the
error message:

Winword.EXE Application Error

The instruction at "0x308e05a0" referenced memory
at "0x0182a27a". The memory could not be "written". Click
OK to terminate etc.

The only way to install my software is to (in VBA editor
on a working machine) REMark out all four instances
of "Variables.Add."
Export code to a floppy.
Go to "fail" machine.
In VBA editor Import code.
Compile code.
Save.
Exit Word.
Restart Word.
In VBA editor UN-REM the four commands.
Compile.
Exit Word.
Restart Word.
Code works (mostly, but one machine has a new fault, but
one thing at a time!).

Incredibly, just importing the file without REMing out the
four commands will crash Word. This happens even if I
DON'T COMPILE OR RUN THE CODE!! It is the mere presence of
the "add variable lines" as imported from a working
machine.

Another failure mode is that provided I don't get
the "referenced memory error" (very rare) Word will delete
the value of one variable, replace it with the value of
the second, and shuffles them all up one!

When it crashes, it is so bad the machines have to be
restarted; closing Word is insufficient.

The 9 computers have a variety of operating systems:
Working: XP, ME, 2000. Non-working: XP, NT4, 2000.

All non-working are networked (different networks for
different parts of the company for which I work). All
working are not networked.

My guess is that something to do with a network is
allocating a memory area that Word VBA also wants to use
to store data about the "Variables.Add".

The question is, how can I make my code work reliably on
the various networked computers we use??

I cannot find any info about this, but surely I am not the
only person to store data in Word variables and use a
network!!

PLEASE help!!!

Thank you

Larry Wallis
 
L

Larry Wallis

Rick, thanks for replying...you are the first to make any
comments at all!!

You offer some interesting ideas which I will follow up.
Since my post, I have been talking to one of our IT guys
and he says he will help next time I go into the office.
He also has some interesting thoughts along the lines
of "turning off the network" (which only IT can do...I
would be popular if I got in there and brought our network
down!!!). He also points out that our networked computers
may be running other software that I don't know about,
that is causing the problem.

Ah well, should have it sorted in 20 years or so!

Thanks again.

Larry
 
C

Cindy Meister -WordMVP-

Hi Larry,

I've never heard of anything like this before, so it's
perhaps not surprising you're having trouble getting help...

1) Are you displaying the Variables' content in the document
using DocVariable fields? If so, where?

2) Could you please show us these code lines that REMing out
"fixes"

3) Are you absolutely certain the problem machines have all
three Service Packs installed?

4) Does the problem occur if Word is run in "safe mode" (with
the \a switch)

5) Does the problem occur if WINDOWS is started in "safe
mode"?

6) Are the templates, or any part of Word, running from the
network? How about any kind of anti-virus or other file
management software?
Incredibly, just importing the file without REMing out the
four commands will crash Word. This happens even if I
DON'T COMPILE OR RUN THE CODE!! It is the mere presence of
the "add variable lines" as imported from a working
machine.

Another failure mode is that provided I don't get
the "referenced memory error" (very rare) Word will delete
the value of one variable, replace it with the value of
the second, and shuffles them all up one!

When it crashes, it is so bad the machines have to be
restarted; closing Word is insufficient.

The 9 computers have a variety of operating systems:
Working: XP, ME, 2000. Non-working: XP, NT4, 2000.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan
24 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 
L

Larry Wallis

Hi Cindy,

Thanks for your input. I can fix many things myself. When
I go "on-line" it is usually for "hard" problems, and I
often have the response "never heard that one before!!".

As with Rick earlier, it is always good to have other
opinions else you can just get "bogged down", which I have.

I have now read the Microsoft article that Rick found
(thanks Rick) and it is similar to my problem, but not
quite the same. However, it is sufficiently close for me
to get our IT man to install SP3 for me as part of our
tests (hopefully next week). I had gone off the idea that
it was not having SP3 installed because one of the
computers in which the code works, is only SP1. I am now
hoping it is the combination of "a network" AND not having
SP3.

The code is rather large (for me anyway...approaching 1000
lines!) so I just post an example of the variables bit and
how I get the data back out. There are other sections of
code that detect whether a variable exists and whether
there is anything in it (to avoid creating several
variables of the same name), but the problem is overcome
by the REMing out of the line shown below (and the 3 other
similar lines elsewhere in the code).

This code is one example (one of the four) that, in this
case, stores the name of the document
in "storeddocumentname":

If Check_Storedvariable_is_Empty("storeddocumentname") =
True Then
'If non existant or empty then prompt for a name using the
default "Name"

documentname = InputBox(messagepromt,
msgTitle, "Name")

'Create new variable & store new name
documentname = Trim(documentname) & Chr$(32) 'Add a
space at the end of name, but avoid more than 1 space
REM OUT THIS LINE: ActiveDocument.Variables.Add
name:="storeddocumentname", Value:=documentname TO HERE

This code gets back "storeddocumentname" from the document
and puts it in documentname" to be inserted into a header
(i.e. this is how, in effect, I view the contents of the
variable):

documentname = ActiveDocument.Variables
("storeddocumentname").Value

With ActiveDocument.Sections(sectioncounter)

If .Headers(wdHeaderFooterPrimary).LinkToPrevious
= False Then 'Only add a header if it is not the same as
previous (otherwise you get several)
.Headers
(wdHeaderFooterPrimary).Range.InsertAfter documentname

I have not tried your other ideas (but will next week, I
hope). And with the IT man I want to investigate how they
may have set up the networked computers.

Thanks again for your comments. At least I now have
something to try (pinning hopes on SP3 at the moment!).

Larry
 

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