Error: This command is not available because no document is open.

RayL

New member
Local time
Today, 14:56
Joined
Sep 24, 2010
Messages
4
We are merging data with a Word doc. Depending on certain conditions, we insert a secind doc and merge more data.

I have been using this this code to do this

Set objWord = GetObject(, "Word.Application")
Set oDoc = objWord.ActiveDocument


The application has been used for about 4-5 years without problems. Suddenly, we started getting this error 4208. Funny thing, though, if I close Outlook the code runs fine with no errors.

Anyone have any thoughts?


Update .... It looks like Word is the culprit. When I turn off Word as the editor in Oultook, the code runs fine. When I open Word before hand and run the code, I get an error.
 
Last edited:
I am not sure why, but in Ac2007, I noticed that Outlook got bonkers if you opened it from VBA code and another version was open already. I wonder if Word has a similar issue?

The solution is to not create another instance of Word if Word is already open. There is a test for that but I am not where I can see that code right now. It will be Monday before I can show you the code I had to use to test for an already-open instance of Outlook. Maybe this code would fix your problem in Word.
 
I am not sure why, but in Ac2007, I noticed that Outlook got bonkers if you opened it from VBA code and another version was open already. I wonder if Word has a similar issue?

The solution is to not create another instance of Word if Word is already open. There is a test for that but I am not where I can see that code right now. It will be Monday before I can show you the code I had to use to test for an already-open instance of Outlook. Maybe this code would fix your problem in Word.

Doc_Man ... thanks for the reply. It looks like the doc has become inactive. Is there a way to tell if it is inactive and, if iso, is there a way to activate it without creating a new instance?

Thanks

Ray
 
I dont know about your direct problem but to use an existing object in office you do something like this..

Code:
On Error Resume Next    ' make sure to change back to other error coding after this
   Set objWord = GetObject(, "Word.Application")   'get existing object
   If Err.Number = 429 Then     'if no instance is running then this will be the error
      'creating a Word object
      Set objWord = CreateObject("Word.Application")
      Err.Clear
   End If
 
Hi RayL,

I see your new to the forum. When someone writes on your question thread then they usually get an email or alert when you write back under the same thread as well. This makes things easier than PMs.

I was only showing you how to do what Doc_man was indicating with instances.

You might have to show more code on what you are doing with these word documents. Do not confuse the Word Application object with your document objects. You only need one Word Application object but you could have many many document objects.

Lets see some code on what you are doing here.

Please bear in mind I do not have experience with your direct problem nor do I know why word and outlook are causing problems.
 
We are merging data with a Word doc. Depending on certain conditions, we insert a second doc and merge data to the second doc.

The merge for the second doc is done in a Sub and we have been using the following code in the Sub to do this.


Code:
Set objWord = GetObject(, "Word.Application")Set oDoc = objWord.ActiveDocument

The error occurrs at this point and states that "The command is not available because no document is open".

Code:
Do While TheEnd = False If rstC!AffNeeded1 = True Then 
objWord.ActiveDocument.Bookmarks("BottomBook").Select 
objWord.Selection.InsertBreak Type:=wdSectionBreakNextPage 
objWord.Selection.InsertFile FileName:= <FileName>

It works fine until the Sub is called.


Thanks

Ray
 
Last edited:
We are merging data with a Word doc. Depending on certain conditions, we insert a second doc and merge data to the second doc.

The merge for the second doc is done in a Sub and we have been using the following code in the Sub to do this.


Code:
Set objWord = GetObject(, "Word.Application")Set oDoc = objWord.ActiveDocument
If this is Document No.2 then you do not need to get objWord again. You must already have it. Use the one you already have.

Further the error message seems pretty obvious to me. There is no active document. But I would need to see more of the code before to see why it is happening.
 
darbid .... thanks for your reply/help. Rermoving the Get objWord staement fixed the problem. I didn't write this code and, as I said before, it ran fine for about 5 years. I've been here for 2 years and never had contact with it before last week. It just worked and everyone was happy. :) We may never know the reason why it worked with that statement included and not work now. Anyway, thanks again for your help.

Ray
 
I am not sure why, but in Ac2007, I noticed that Outlook got bonkers if you opened it from VBA code and another version was open already. I wonder if Word has a similar issue?

The solution is to not create another instance of Word if Word is already open. There is a test for that but I am not where I can see that code right now. It will be Monday before I can show you the code I had to use to test for an already-open instance of Outlook. Maybe this code would fix your problem in Word.

another instance where old advice worked for today. I've been plugging away at a create nested tables vba and this error kept popping for me even though the document appeared open to me. Low and behold there were some orphan word instances open. Killed them all via task manager and no issues.
 

Users who are viewing this thread

Back
Top Bottom