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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check if there is a document open in VBA Word 2003

Status
Not open for further replies.

DellHater

Programmer
Nov 24, 2006
75
CZ
HI

I have many word files that use a common macro, at the end of the macro I want to close the current document (if there is anything open). Sometimes there is a document to close, sometimes not.
How do I check to see if there is anything open ?
I've tried doing

If len(activeDocument.path) <> 0
but it doesn't like it as there is no active document.

any ideas appreciated.

thanks
 
You might want to have a look at Word's Documents collection.
 
I am confused.

"Sometimes there is a document to close, sometimes not."

Are you saying you are executing Word VBA code with NO document open? Odd that.

"I want to close the current document "

The current active document is...ActiveDocument.

If the "current" document is not active - and why would that be? - please define "current".

In any case, follow strongm's suggestion. Look up the Documents collection. In all cases, it is MUCH better to work with defined, explicit, document objects. That way, you can name them, and action them by name - regardless of whether it is active, or not.

"but it doesn't like it as there is no active document." Odd that. You are actioning VBA code with no documents. Ummm, what are you doing?

"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