Code for closing Word

H

H Dodson

I have been attempting to get a macro together that will do the following:
1.Unprotect a document (if protected)
2.Select the document
3. Copy the document
4.Close the document
5.Supress the save prompt
and will several individual's assistance from this discussion board I have
gotten that macro. The question I have now is, Can I close Word as the last
step of the macro (not just close the document.) Here is the code that I
have been using: (thank you all for your help!)

Dim oDoc As Document

Set oDoc = ActiveDocument
If oDoc.ProtectionType <> wdNoProtection Then
oDoc.Unprotect
End If
oDoc.Content.Copy
oDoc.Close SaveChanges:=wdDoNotSaveChanges
 
G

Greg Maxey

H,

Just a minor change:

Dim oDoc As Document

Set oDoc = ActiveDocument
If oDoc.ProtectionType <> wdNoProtection Then
oDoc.Unprotect
End If
oDoc.Content.Copy
Application.Quit SaveChanges:=wdDoNotSaveChange­s
 
H

H Dodson

Thanks Greg!
This is what I ended up going with and it seems to work fine:

Dim oDoc As Document

Set oDoc = ActiveDocument
If oDoc.ProtectionType <> wdNoProtection Then
oDoc.Unprotect
End If
oDoc.Content.Copy
oDoc.Close SaveChanges:=wdDoNotSaveChanges
If Documents.Count = 0 Then Application.Quit
End Sub
 
H

H Dodson

Now that I have a working macro, any tips on the quickest way to get it to my
co-workers? As it is now I create a macro and paste the code on each
station. I know there is a more automated manner!
 
G

Graham Mayor

Provide a global add-in template containing the code. You only need the one
copy if the workstations are on a network.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
B

Ben M

Is this a very wise move? What if you have other documents open and this
macro is run. Say goodbye to the work in your other documents!!
 
G

Greg

Ben,

You are right. It isn't the wisest move. To tell you the truth I was
in a hurry and I just answered the question asked and didn't, as you
pointed out, offer the best answer. I looks like Howard figured that
out for himself.
 
C

Curt

I have a similar problem Have tryed all suggestions I can find here. What I
end up with is after print the close window for printer is open. You must
select close window then you still have to close word. Word does not show a
document per say. it has the browned out screen. Here is what I've tryed. If
you can advise this stumped one I sure would appreciate it.
Thanks

Execute Pause:=True
'ActiveWindow.Close
ActiveDocument.Close wdDoNotSaveChanges
' ActiveWindow.Close
Application.Quit
End With
ActiveWindow.Close
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
If Documents.Count = 0 Then Application.Quit
' Application.Quit SaveChanges:=wdDoNotSaveChanges
'Application.Quit
 

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