Re: Help with 'Save' command in VBA
- From: "Shauna Kelly" <ShaunaKelly@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 19 Jan 2008 14:05:22 +1100
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
.
- Prev by Date: Re: calendar in word
- Next by Date: Re: Textboxes and their influence on the behaviour of ranges
- Previous by thread: Re: calendar in word
- Next by thread: Re: macro to copy clipboard to autocorrect entry, Word 2003
- Index(es):
Relevant Pages
|