disable autoexec then I double-click a document?

E

eric

Hi!

I have a solution where I open customized dialog when I open Word (or select
a new document). I trigger this from the autoexec event when I open Word,
but I don't want it to run if I open Word by double-clicking an existing
Word-document....:/

Any ideas?

Thanks!

/e
 
E

eric

Thanks, but does that trigger when I start Word as well? (I can't modify
normal.dot.)

/e
 
D

Doug Robbins - Word MVP

Put the autoexec macro in a template that you save in the Word\Startup
folder.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
E

eric

Hi!

But how does it work if I open Word by doublecklicking an existing document?
In that case I don't want my dialog to open.

/e
 
D

Doug Robbins - Word MVP

Have you tried it?

I do not know how it works, but with an Add-in (a template stored in the
Word Startup folder), an autoexec macro in that template does not "fire" if
Word is started by double clicking on a document or if Word is set as the
editor in Outlook and Outlook is started before Word.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
E

eric

I don't think I follow. If I put the following code in test.dot and put
test.dot in the startup folder it fires both when I just start Word or when
I doubleclick a document. Or am I missing something?

Sub autoexec()
MsgBox "auto"
End Sub

/e
 
T

Tony Jollans

I have to disagree with Doug here.

An autoexec in a template fires when that template is loaded - unless auto
macros are disabled. Automacros can be disabled in code and are sometimes
automatically disabled, for example during automation.

When Word starts normally, templates in the startup folder are loaded and so
autoexec macros in them are run. When you double click on a document - and
Word is not already running - Word will first be started normally just as if
you had started it without a document, and then the document you
double-clicked will be opened. I don't know of any way to distinguish the
two situations and have the macro run in one case and not the other.

Why do you want the different behaviours?
 
E

eric

Thanks!

Well something like this:

1) I start Word. Then I want to automatically display my dialog from where I
choose from various new templates (and make some more choises). Autoexec
handles that.

2) I have Word started and select a new document. Same as above with
autonew.

3) If a start Word by double clicking a document though, I (obviously) don't
want my dialog to show because then I want to work with the document I
double clicked.

Don't know it theres a way around this... :/

/e
 
T

Tony Jollans

Don't know it theres a way around this... :/

Neither do I, I'm afraid.

Before getting that far, though, I'm not entirely sure that everything else
you describe is possible. Where do you have your Autonew macro if, as you
say (although this shouldn't be the case), you can't modify your normal.dot?

I'm not clear what you want to do every time a new document is created,
regardless of the template on which it is based, and am also unclear as to
what, if anything, you have working yet.
 
D

Doug Robbins - Word MVP

Hi Tony,

Try the add-in to merge documents to separate files with the filename taken
from a field in the data base that you can down load from Graham Mayor's
website.

It contains the following:

Dim AppClass As New MergeApplication
Public Sub AutoExec()
Set AppClass.app = Word.Application
End Sub
Sub ActivateEvents()
Set AppClass.app = Word.Application
End Sub
Sub DeactivateEvents()
Set AppClass.app = Nothing
End Sub

If Word is started by double clicking a on a document or as the editor for
Outlook, it doesn't work. Maybe I had put this down to a failure of the
AutoExec, but it may have be a failure of the ActivateEvents.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
R

Russ

Eric,
Maybe you could intercept the global Word save routines to interject the
disable autoexec code into the local ThisDocument 'when opened' routine of
the documents being saved? But I'm not sure which events get fired off
first. Maybe the local document 'when opened' startup disable code won't be
read before the global Word startup code.
 
R

Russ

Eric,
Even if what I posted worked, you'd need a way to re-enable autoexec code
after a double-clicked document is fully opened.
 
R

Russ

Eric,
Put this subroutine in the ThisDocument of a Global template in Office
Startup folder:
Sub AutoExec()
If ActiveDocument.BuiltInDocumentProperties(wdPropertyCharacters) = 0 Then
MsgBox "Run Code"
Else
MsgBox "Don't Run Code"
End If
End Sub

It should control what Word does when first starting up. It doesn't handle
blank document initialization after Word is running, for that you might be
forced to use an AutoNew() in the Normal.dot.
 
T

Tony Jollans

Hi Doug,

Word in Outlook causes all sorts of confusion (and I can't check right this
minute because the machine with Word 2003 I can get on has Outlook 2000) but
when I install your AddIn it works exactly the same whether I start Word
alone or by double clicking an existing document - as I would expect. I
haven't studied the code but I am interested to know any more you can tell
me about the environment where you see the difference.
 
D

Doug Robbins - Word MVP

Hi Tony,

The issue came up when a number of people were testing the add-in before we
made it public and there were a number for whom it did not work - Graham
Mayor was one, but there were others. Eventually, we tracked it down to
that way in which Word was being started.

Since then, there have been a few of the several thousand who have
downloaded the add-in have come back with the issue of it not working and in
at least some of these cases, getting them to start Word from the Start menu
has overcome the problem.

I must admit, that trying just now with Word 2007, started by double
clicking on a document in Windows Explorer, the add-in works fine.

Guess I'll have to refrain from repeating the advice that I had given.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
T

Tony Jollans

Thanks, Doug,

Interesting! To the best of my knowledge there is not, nor ever has been,
any difference directly due to opening Word with a document as opposed to
without. A couple of possibilities spring to mind (a) if you open a
document there may be macros in it or an attached template which interfere
somehow or (b) the command string set up to Open a document may differ from
the one in the normal Word shortcut.
 
R

Russ

Eric,
Thanks, but it fires before the doc opens (ie get an error).
What does the error message say?
Maybe it is just a timing issue, but on older G4 Macintosh I don't get an
error. It may depend on the speed of the computer or how lengthy the
documents are and the time they need to load completely. You could generate
a pause within the macro before testing 'ActiveDocument'. Also, are you
using the piece of code in the ThisDocument module of a global template?
 
E

eric

Russ,

I really appreciate your help, I modified your code some and it seems to
work, then Graham came up with a slightly different solution that seems to
work even better so I *think* I'm on track now.

Grahams solution looks like this:

--
Sub AutoExec()
On Error GoTo Error:
If Left(ActiveDocument.Name, 8) = "Document" Then
ActiveDocument.Close
' open dialog
End If
Error:
End Sub
--

Again, many thanks for your help.

Best,
/e
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top