Word VBA from Access (1 Viewer)

ChislePip

Registered User.
Local time
Today, 20:41
Joined
Mar 14, 2014
Messages
14
I've developed VBA code in Access 2007 which starts a 'hidden' Word session, does stuff, and then quits the Word session. All works fine except under 2 scenarios - (A) If there is another 'normal' Word session running prior to the code running and (B) If a 'normal' Word session starts whilst the code is already running.
Under the (A) scenario, when the code attempts to quit Word, the dialog "Word cannot save this file because it is already open elsewhere .... Normal.dotm" is displayed, which I cannot trap. To workaround this, I've tried (i) using
Code:
objApp.NormalTemplate.Saved = True
which doesn't appear to work (same error), (ii) using a template other than "Normal.dotm" in the documents used by the code, which doesn't work either (same error), and (iii) considered using Word's command line switches - which I don't think can be used when issuing a
Code:
Set objApp = CreateObject("Word.Application")
. So I'm stuck on this.
Under the (B) scenario, when launching a document whilst code is running, then this uses the 'hidden' session, rather than a new Word session, and is therefore unusable. So, I'm stuck on this too!!

I have faith that one of you can help me!!
 

Cronk

Registered User.
Local time
Today, 20:41
Joined
Jul 4, 2013
Messages
2,772
I'd like to maintain the faith, brother. :-}

"does stuff"? Care to elaborate. You trying to save a template, or a file based on the template? Maybe you are using objDoc.save rather than objDoc.saveas "filename".
 

ChislePip

Registered User.
Local time
Today, 20:41
Joined
Mar 14, 2014
Messages
14
Thank you for responses. Well, "does stuff" refers to the building of documents which are saved. All documents are saved OK (using SAVEAS), then all I want to do is 'quit' the session. No attempts to save any templates.
 

Cronk

Registered User.
Local time
Today, 20:41
Joined
Jul 4, 2013
Messages
2,772
Presuming you open your Word session as
Code:
Set objWordApp = ...
then close the session by using
Code:
objWordApp.quit
 

ChislePip

Registered User.
Local time
Today, 20:41
Joined
Mar 14, 2014
Messages
14
Yes, that's how I'm trying to quit Word. I've also tried quitting with
Code:
objApp.Quit SaveChanges:=wdDoNotSaveChanges
, but that appears to relate to saving dirty document changes, rather than template changes.
 

Users who are viewing this thread

Top Bottom