Re: Help with 'Save' command in VBA

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Ellen

As a general rule, avoid using ActiveDocument more than once in any
macro, since Word can change its mind about what document is active.
And, since the PrintOut method can be applied to a specific document,
you can be 100% sure of what you're printing, by applying it to your
document, rather than the whole Word application. Try something like
this:

Dim oDoc as Word.Document

Set oDoc = ActiveDocument

if oDoc.Saved Then
oDoc.PrintOut ' ... etc, but omit the FileName parameter. Indeed, you
can probably omit most of the parameters.

oDoc.Save

end if

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word



"EllenM" <EllenM@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5D85E071-617C-4231-A285-2F842BC5A54C@xxxxxxxxxxxxxxxx
Hello,

I am trying to create a macro that saves a file after the file has
been
printed to avoid the prompt which typically appears onscreen which
asks the
user if they want to save the current open file. As you know, Word
will
prompt you to save a file that you had already saved if you attempt to
close
the file after it has been printed. Printing the file seems to store
printer
data into the file which of course would technically count as a
changed file,
subsequently prompting the user to save changes. I try to avoid this
message
prompt with the "ActiveDocument.Save" command at the last line of the
subroutine below. The problem is that it does not seem to work. I am
still
prompted to save anyway even when saving after programmatically
invoking the
print command. Can someone shed some light on this? Thanks!

If ActiveDocument.Saved = True Then
Application.PrintOut Filename:="", Range:=wdPrintAllDocument, Item:=
_
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True,
PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0,
PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0

ActiveDocument.Save
End If


Ellen


.



Relevant Pages

  • Re: Macros Containing a File Save As & Tab Deletions
    ... you can avoid the prompt: ... I have a macro that saves off a copy of the file, ... I delete a few tabs from the copy. ...
    (microsoft.public.excel.misc)
  • Re: Track "WINWORD.EXE" VB
    ... To avoid using the ActiveDocument object, ... Dim appWord As Word.Application ... Dim docTarget As Word.Document ...
    (microsoft.public.word.vba.general)
  • Re: Required Fields
    ... prompt, save the item after you generate the ... >> Is there a way to programatically turn on the required flag for a ... How can I avoid this? ...
    (microsoft.public.outlook.program_forms)
  • ksh read prints newline after signal receipt
    ... Does anyone know how I can avoid that ksh-read issues a newline upon ... waiting for the script user to enter a command at a prompt. ... cursor one line after the prompt. ...
    (comp.unix.shell)
  • Re: IIS 6.0 Host Headers and Kerberos
    ... You merely wish to avoid the prompt from Internet Explorer? ... should I put the various setspn and adsutil settings ...
    (microsoft.public.inetserver.iis.security)