Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close application only if other documents are not open 2

Status
Not open for further replies.

RP1America

Technical User
Aug 17, 2009
221
US
I have a VBA that when the user presses the 'OK' button, it opens, inserts text, saves and closes them.

I would like to be able to completely close down Word, yet only if the user has no other Word docs open.

When I use ActiveDocument.Close, it closes the document that the VBA code is stored in yet leaves the Word application open.

When I use Application.Quit, it closes the Word application, regardless if the user has other docs open not pertaining to this VBA.

So, no other docs open = word application closes...
other docs open = application stays open, yet active document closes.

Any ideas?
 
in essence you could try something like
if application.windows.count >1 then
activedocument.close
else
application.quit

i appologise if the syntax etc isn't quite right but it is word!

;-)
If a man says something and there are no women there to hear him, is he still wrong? [ponder]
How do I get the best answers?
 
i appologise if the syntax etc isn't quite right but it is word! "

Hey! That is perfectly good and reasonable syntax. Nothing strange about Word in this regard. Although, I would actually test agaijnst the Document count, rather than the Windows.count - since it is the existence of open documents that is the issue.
Code:
Sub yadda()
If Documents.Count > 1 Then
   [COLOR=red]'  more than one doc open[/color red]
   ActiveDocument.Close
Else  [COLOR=red]' count = 1[/color red]
   ActiveDocument.Close
   Application.Quit
End If
End Sub

"A little piece of heaven
without that awkward dying part."

advertisment for Reese's Peanut Butter Cups (a chocolate/peanut butter confection)

Gerry
 



Sub yadda()

I prefer
Code:
Sub liminal()
 'yadda
;-)

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
fumei
fair point re testing doc rather than window.

and i just knew you'd bite at the syntax thing! not here as often as once was but some things are sooooo reliable! looking forward to the (winter) olympics on your doorstep? want the summer ones in 2 years too?

on the other thing i prefer
Code:
Sub lime
or
Code:
Sub mit
or
Code:
Sub stance
or
Code:
Sub terfuge
or
Code:
Sub standard

yadda yadda.....!

;-)
If a man says something and there are no women there to hear him, is he still wrong? [ponder]
How do I get the best answers?
 



and the proverbial
Code:
Sup poena()
  'gocha by the b...s
end sub

Skip,
[sub]
[glasses]Just traded in my old subtlety...
[b]for a NUANCE![/b][tongue][/sub]
 
Ok...stop now.

Loomah, welcome back. Geez, am I SO predictable?

"A little piece of heaven
without that awkward dying part."

advertisment for Reese's Peanut Butter Cups (a chocolate/peanut butter confection)

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top