VBA close down all open word docs

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,113
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I'm trying to find a vba code that will close down all open word documents.

Can anyone post?

Thank you!
pinaceous
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hey *Skyybot!

I'm getting an error with that code.

I thought it was something with my Reverences?

But when I check off my Microsoft Office 16.0 Object Library, it still gives me an error.

Thanks,
pinaceous
 
Upvote 0
Are you trying to do this from within Excel?
 
Upvote 0
Hi Peter_SSs,

Yes, I'm running an excel sub that requires that all open word documents close.

Do you have a code for this type of situation?? Because the one above did not work.

Kindly let me know.

Thank you!

Respectfully,
pinaceous
 
Upvote 0
Hey *Skyybot!

I'm getting an error with that code.

I thought it was something with my Reverences?

But when I check off my Microsoft Office 16.0 Object Library, it still gives me an error.

Thanks,
pinaceous
What error are you getting?
 
Upvote 0
I'm getting no error or nothing at all.

But I think this might work.

VBA Code:
Sub CloseWord()

    Dim W As Object
    On Error Resume Next
    Set W = GetObject(, "Word.Application")
    If W Is Nothing Then Exit Sub
    W.ActiveDocument.Close SaveChanges:=False
    W.Quit
    Set W = Nothing
 
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,028
Messages
6,122,749
Members
449,094
Latest member
dsharae57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top