Word 2K Code Causing Word 2K3 Exceptions

T

TheDoctor

Good afternoon!

A client of mine wrote the same VBA code into hundreds of Word 2000
documents that queries the user that opens the doc for a lot number, which is
then inserted into the document as a bar code.

When these documents are opened in Word 2003, they throw an exception.

If we open the document w/o running the macros, unlock the code, then lock
it again, the Word 2003 documents work perfectly, without throwing an
exception. However, we have hundreds of these to do... We'd rather have
another process.

Any ideas?

Thanks in advance,
Mark
 
P

Peter Huang

Hi Mark,

What exact error message do you get?
Have you tried to create a new word 2003 document and then copy and paste
the macro code into the document to see if the problem persists?
If the problem persists, can you provide a reproduce sample document?


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

TheDoctor

Hi, Peter,

I have a screen shot of the exact error message, along with detail
described. The first error is "Microsoft Office Word has encountered an
error..." The data in the error report includes:
AppName: Winword.exe
ModName: vbe6.dll

The cut-and-paste question.
I tried this today using the code from a "problem" document and did not have
any problems with the new file when I initially open it. However, when I make
the following changes.

Change,
ActiveDocument.Bookmarks("DateValue").Select
Selection.TypeText Format(Date, "dd mmmm yyyy")
To
ActiveDocument.Bookmarks("DateValue").Select
Selection.TypeText Date

Save and Open -> document works fine

Then change
ActiveDocument.Bookmarks("DateValue").Select
Selection.TypeText Date
Back to
ActiveDocument.Bookmarks("DateValue").Select
Selection.TypeText Format(Date, "dd mmmm yyyy")

Save and Open -> I get the error.

When I remark out the code
' ActiveDocument.Bookmarks("DateValue").Select
' Selection.TypeText Format(Date, "dd mmmm yyyy")

Save and Open -> document is fine

Change the code again to
ActiveDocument.Bookmarks("DateValue").Select
Selection.TypeText Format(Date, "dd mmmm yyyy")

Save and Open -> document is fine

With the new document, I have not protected the code. One "feature" of the
problem documents are that when I close Word. The temp files stick around and
I end up deleting them. Deleting the temp file does not solve the problem.
 
P

Peter Huang

Hi

From your description it seems that the problem is caused by the code below.
Selection.TypeText Format(Date, "dd mmmm yyyy")
and
Selection.TypeText Date

From the office vba help, we will know that the Date function will return
Variant while the TypeText need string.
You may find that by press F1 on the keyword in the vba editor.

Although VBA is very smart , but I think we would better follow the
struction.

I think you may try to use the correct string type.
e.g.
dim str as string
str = cstr(date)
Selection.TypeText str

You may have a try and let me know the result.



Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

Cindy M -WordMVP-

Hi Peter,

Forgive me for jumping in, here, but the Format function returns a string, so
I don't think this can be the problem in the case where the code uses Format.
The Format function is explicitly designed to convert numbers and dates into
literal strings.
From your description it seems that the problem is caused by the code below.
Selection.TypeText Format(Date, "dd mmmm yyyy")
and
Selection.TypeText Date

From the office vba help, we will know that the Date function will return
Variant while the TypeText need string.
You may find that by press F1 on the keyword in the vba editor.

Although VBA is very smart , but I think we would better follow the
struction.

I think you may try to use the correct string type.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

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

Cindy M -WordMVP-

Hi Mark,

From my experience, I have a hard time imagining what the problem might be,
here. My inclination is that there may be a problem in Normal.dot or in the Word
installation. If you
- copy the code lines in question to a Notepad text file
- start Word in SAFE MODE (use the /a switch)
- paste the code lines in from the Notepad file and run your test

Are things stable?

How about running Help/Detect and Repair?

Side note: You're not using the most efficient method to put text into a
bookmark. No need to jump to the bookmark:
ActiveDocument.Bookmarks("DateValue").Range.Text = Format(Date, "dd mmmm
yyyy")
I have a screen shot of the exact error message, along with detail
described. The first error is "Microsoft Office Word has encountered an
error..." The data in the error report includes:
AppName: Winword.exe
ModName: vbe6.dll

The cut-and-paste question.
I tried this today using the code from a "problem" document and did not have
any problems with the new file when I initially open it. However, when I make
the following changes.

Change,
ActiveDocument.Bookmarks("DateValue").Select
Selection.TypeText Format(Date, "dd mmmm yyyy")
To
ActiveDocument.Bookmarks("DateValue").Select
Selection.TypeText Date

Save and Open -> document works fine

Then change
ActiveDocument.Bookmarks("DateValue").Select
Selection.TypeText Date
Back to
ActiveDocument.Bookmarks("DateValue").Select
Selection.TypeText Format(Date, "dd mmmm yyyy")

Save and Open -> I get the error.

When I remark out the code
' ActiveDocument.Bookmarks("DateValue").Select
' Selection.TypeText Format(Date, "dd mmmm yyyy")

Save and Open -> document is fine

Change the code again to
ActiveDocument.Bookmarks("DateValue").Select
Selection.TypeText Format(Date, "dd mmmm yyyy")

Save and Open -> document is fine

With the new document, I have not protected the code. One "feature" of the
problem documents are that when I close Word. The temp files stick around and
I end up deleting them. Deleting the temp file does not solve the problem.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

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

Peter Huang

Hi Cindy,

Thank you for you input.
If we look into the VBA help, we will find that the Format will return
Variant (String), whose type is somewhat different from String.
In the COM Level, the String is BSTR while the Variant(String) is
Variant(its subtype is string(bstr)).

Commonly VBA will be smart enough to do the convertion.

Now so far to troubleshooting the problem so I suggest Mark to concern the
format return to string type first.
Also to isolate the problem, we would better run the code one method call
by one.
i.e.
Break the code below into two.
Selection.TypeText Format(Date, "dd mmmm yyyy")

e.g.
dim str as string
str = cstr(date)
Selection.TypeText str




Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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