Re: VBA Word 2003 File Close



It would be better to declare a variable as a Document and set that variable to the document that you are opening rather than rely on the active document. So assuming you declared Source as that variable with

Dim Source as Document

and then when you opened the document you used

Set Source = Documents.Open("FileName")

the when finished with that document, use

Source.Close wdDoNotSaveChanges

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"David Schnelbaker" <DavidSchnelbaker@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:10BFBA6E-D5DD-4670-B82B-EA8A483905E4@xxxxxxxxxxxxxxxx
Word 2003,

In a Word 2003 template document I have a macro triggered by a CheckBox
event template that opens up another document, grabs data in that second
document and then is supposed to close that second document.
When I run the macro from the VBA editor it works exactly as designed with
no errors. But when the Macro is triggered as a result of the CheckBox
status change, I get a run-time error 4198 "Command Failed" at the line that
closes the document.

The offending line is just "ActiveDocument.Close (False)". I have put a
MsgBox with the describing the ActiveDocument so I know it is the right doc
that I am trying to close.

Any ideas?

.



Relevant Pages

  • Re: Searching for text within formula
    ... it figures that as soon as I declare something working ... ... stops working. ... When I run the macro, ... Run-time error '1004' ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Declaring Objects
    ... What this is saying is set the Colors variable to refer to the Colors sheet, ... > that I need to declare my objects and know that I would prefer to declare ... > Below is my first attempt to writing a macro, ... > Sub FindAndReplace() ...
    (microsoft.public.excel.programming)
  • Re: Converting C to Delphi
    ... macro and a million constants. ... Can this be imported into delphi or do I ... > Perform those calculations yourself and declare the constants with the ... One is temp, ...
    (alt.comp.lang.borland-delphi)
  • Re: Loop problem
    ... (declare (special a b)) ... will need a macro to type in the nest of dolists for you. ... The macroexpander will say "Oh I'm not finished yet." ...
    (comp.lang.lisp)
  • Re: one simple question
    ... You'll most likely find a macro called NULL in one of the Visual C++ ... this doesn't declare a function. ... Empty brackets would be equivalent to replacing the "null" with "void", ... also making this a function declaration. ...
    (comp.lang.cpp)