VBA code for closing document is performing wrong task

L

Larry

Lately in my Word 97 I've been having a problem with a macro which is a
customized version of DocClose in which I do some other steps in
addition to closing the document. The code used to close the document
is

WordBasic.DocClose

I've also used ActiveDocument.Close for this.

Here's what happens. When I run this customized DocClose macro using
Ctrl+W, if the active document is an unsaved document with changes, I
get the SaveAs dialog box instead of the message saying, "Do you want to
save the changes you made to Document2? If the active document is a
saved document with unsaved changes, running the DocClose macro
automatically saves the changes and closes the document!

If I comment out all the other code in the macro, leaving only
WordBasic.DocClose or ActiveDocument.Close, the problem persists. So
the problem is definitely in those two commands.

The only way I can fix the problem is to rename the DocClose macro as
something else so that Ctrl+W. is running the built-in DocClose command
again.

I've had this macro for a long time and it never gave me trouble before.
Using WordBasic.Close always worked exactly like using the built-in
DocClose command.

Also, I re-merged the Word Data key in the Registry, but that didn't
help.

Any ideas?

Thanks,
Larry
 
H

Helmut Weber

Hi "Larry",

If you want to close a document
without saving and without being asked for a proper name,
if the document's path is still the empty string "",
set it's saved-property to true.

if activedocument.path = "" then
ActiveDocument.Saved = True
ActiveDocument.Close
endif

I wonder, whether this was different with Word 97.



Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
L

Larry

Also, I should mention that WordBasic.DocClose is the code that results
if you create a macro based on the built-in command DocClose. Yet, as I
said, the macro misbehaves, while the built-in command works normally.
 
L

Larry

Thanks, but I don't want to create a new macro, and I don't want to
close an unsaved document without being prompted whether I want to save
it or not. I want to fix the existing code. Why are both

ActiveDocument.Close and WordBasic.FileClose

operating incorrectly?
 

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