Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

disable autoexec then I double-click a document?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
eric - 10 Oct 2006 12:38 GMT
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
Stefan Blom - 10 Oct 2006 14:00 GMT
Have you tried putting the code which loads the user form in an
AutoNew sub instead? See
http://word.mvps.org/faqs/macrosvba/DocumentEvents.htm and Word VBA
Help.

Signature

Stefan Blom
Microsoft Word MVP

> Hi!
>
[quoted text clipped - 8 lines]
>
> /e
eric - 11 Oct 2006 14:45 GMT
Thanks, but does that trigger when I start Word as well? (I can't modify
normal.dot.)

/e

> Have you tried putting the code which loads the user form in an
> AutoNew sub instead? See
[quoted text clipped - 16 lines]
>>
>> /e
Doug Robbins - Word MVP - 11 Oct 2006 16:40 GMT
Put the autoexec macro in a template that you save in the Word\Startup
folder.

Signature

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

> Thanks, but does that trigger when I start Word as well? (I can't modify
> normal.dot.)
[quoted text clipped - 21 lines]
>>>
>>> /e
eric - 12 Oct 2006 09:37 GMT
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

> Put the autoexec macro in a template that you save in the Word\Startup
> folder.
[quoted text clipped - 24 lines]
>>>>
>>>> /e
Doug Robbins - Word MVP - 12 Oct 2006 12:26 GMT
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.

Signature

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

> Hi!
>
[quoted text clipped - 31 lines]
>>>>>
>>>>> /e
eric - 16 Oct 2006 08:21 GMT
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

> Have you tried it?
>
[quoted text clipped - 38 lines]
>>>>>>
>>>>>> /e
Tony Jollans - 16 Oct 2006 11:05 GMT
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?

--
Enjoy,
Tony

> 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
[quoted text clipped - 68 lines]
> >>>>>>
> >>>>>> /e
eric - 16 Oct 2006 12:24 GMT
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

>I have to disagree with Doug here.
>
[quoted text clipped - 95 lines]
>> >>>>>>
>> >>>>>> /e
Tony Jollans - 16 Oct 2006 13:23 GMT
> 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.

--
Enjoy,
Tony

> Thanks!
>
[quoted text clipped - 114 lines]
> >> >>>>>>
> >> >>>>>> /e
eric - 25 Oct 2006 09:24 GMT
Okie don't hang me here but can I possibly use this?

Sub AutoExec()
On Error GoTo errHandler
If ActiveDocument.BuiltInDocumentProperties(wdPropertyCharacters) = 0 Then
   ActiveDocument.Close SaveChanges:=False
   MsgBox "Yah..."
End If
Exit Sub
errHandler:
Select Case Err.Number
       Case 4248
           Exit Sub
       Case Else
           MsgBox "Error bla bla"
   End Select
End Sub

>> Don't know it theres a way around this... :/
>
[quoted text clipped - 150 lines]
>> >> >>>>>>
>> >> >>>>>> /e
Tony Jollans - 25 Oct 2006 11:08 GMT
> can I possibly use this?

When and from where, and to do what?

Why don't you try it?

To be honest, I doubt it will help you but I'm still unclear as to your
objective and what, if anything, you have working so far. Customizing
FileNew is certainly possible. Overriding the new document created by
default at startup is very tricky.

--
Enjoy,
Tony

> Okie don't hang me here but can I possibly use this?
>
[quoted text clipped - 168 lines]
> >> >> >>>>>>
> >> >> >>>>>> /e
eric - 25 Oct 2006 14:55 GMT
I have this customized dialog I want to open when Word opens but not if I
open Word by double-clicking a document.

/e

>> can I possibly use this?
>
[quoted text clipped - 206 lines]
>> >> >> >>>>>>
>> >> >> >>>>>> /e
Graham Mayor - 25 Oct 2006 15:20 GMT
How about?

Sub AutoExec()
On Error GoTo Error: 'Double click document
If Left(ActiveDocument.Name, 8) = "Document" Then
MsgBox "New Document"
End If
Error:
End Sub

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> I have this customized dialog I want to open when Word opens but not
> if I open Word by double-clicking a document.
[quoted text clipped - 178 lines]
>>>>>>>>>>>>>
>>>>>>>>>>>>> /e
Tony Jollans - 25 Oct 2006 23:20 GMT
Hi Eric,

I'm not trying to be difficult but what is it that you want to do in this
dialog? I'm finding it hard to imagine what gain could be worth the effort
and wondering if there might not be an alternative approach.

When Word starts  I think it loads normal.dot and runs any autoexec in it,
then creates a new document (but does not run autonew) and then loads global
templates and AddIns and runs any auto macros in them. AFAIK, however, the
precise order of events is not documented and may or may not be consistent.
If I am correct then your macro should work but the property check seems a
bit convoluted and whilst it may work for you it certainly doesn't uniquely
identify a new document. Maybe someone who knows more than me can step in
and provide more detail.

--
Enjoy,
Tony

> I have this customized dialog I want to open when Word opens but not if I
> open Word by double-clicking a document.
[quoted text clipped - 211 lines]
> >> >> >> >>>>>>
> >> >> >> >>>>>> /e
Graham Mayor - 26 Oct 2006 06:46 GMT
Tony
As I posted in my last message - When Word is opened it creates a blank
document. You can test for this document with an Autoexec macro in an
add-in. If you open Word by clicking on a document the blank document is not
created and the autoexec still runs but produces an error message. You can
trap that error message. The example code I used simply pops up a message
box - but it could be expanded, but like you I am at a loss to understand
the merits of this requirement.

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Hi Eric,
>
[quoted text clipped - 212 lines]
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> /e
eric - 26 Oct 2006 08:04 GMT
Cool solution!

I guess this is better then mine...

It seems to work even if I open a document that's named "Document"?

Best
/e

> Tony
> As I posted in my last message - When Word is opened it creates a blank
[quoted text clipped - 221 lines]
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> /e
Tony Jollans - 26 Oct 2006 16:21 GMT
Thank you Graham.

So, rather than faffing about with error trapping wouldn't it be easier to
check Documents.Count for being zero?

Sub AutoExec()
   If Documents.Count > 0 Then
       Debug.Print "New document has been created"
   End If
End Sub

However, none of these solutions are guaranteed as it depends what other
code is running, although they may work in particular environments.

As a user, I generally hate this kind of imposed customisation (which is
usually attempted as a substitute for training) and am happy that, were I a
user, I could circumvent it.

--
Enjoy,
Tony

> Tony
> As I posted in my last message - When Word is opened it creates a blank
[quoted text clipped - 229 lines]
> >>>>>>>>>>>>>>
> >>>>>>>>>>>>>> /e
Graham Mayor - 27 Oct 2006 07:56 GMT
That's certainly neater and works in much the same way - and I agree with
your wider comments.

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Thank you Graham.
>
[quoted text clipped - 251 lines]
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> /e
eric - 26 Oct 2006 07:47 GMT
Hi Tony,

Many thanks for your time.

I have a start-dialog-solution from where I want users to choose from (many)
various (customized) templates. Some settings are general for all templates
so I set them in the dialog (language etc). The thing is that this should be
the *only* allowed way for a user to open a template. So when Word is
started, if the user selects a new document the dialog should open (this
works fine).

But the dialog should also (preferably) open when the user opens Word, hence
my problem. Because if the user opens Word by double-clicking a document I
(of course) don't want the dialog to open.

If there's no way around this I'll have to open a "standard template" when
Word starts, but if I have a choice I want to avoid this.

Best

/e

> Hi Eric,
>
[quoted text clipped - 257 lines]
>> >> >> >> >>>>>>
>> >> >> >> >>>>>> /e
Doug Robbins - Word MVP - 16 Oct 2006 13:27 GMT
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.

Signature

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

>I have to disagree with Doug here.
>
[quoted text clipped - 95 lines]
>> >>>>>>
>> >>>>>> /e
Russ - 16 Oct 2006 17:56 GMT
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.

> Hi Tony,
>
[quoted text clipped - 18 lines]
> 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.

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Russ - 16 Oct 2006 18:08 GMT
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.
> Eric,
> Maybe you could intercept the global Word save routines to interject the
[quoted text clipped - 25 lines]
>> 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.

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Russ - 17 Oct 2006 06:57 GMT
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.

> Eric,
> Even if what I posted worked, you'd need a way to re-enable autoexec code
[quoted text clipped - 28 lines]
>>> 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.

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

eric - 25 Oct 2006 09:03 GMT
Thanks, but it fires before the doc opens (ie get an error).

/e

> Eric,
> Put this subroutine in the ThisDocument of a Global template in Office
[quoted text clipped - 49 lines]
>>>> the
>>>> AutoExec, but it may have be a failure of the ActivateEvents.
Russ - 25 Oct 2006 17:51 GMT
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
>
[quoted text clipped - 51 lines]
>>>>> the
>>>>> AutoExec, but it may have be a failure of the ActivateEvents.

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

eric - 26 Oct 2006 08:33 GMT
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

> Eric,
>> Thanks, but it fires before the doc opens (ie get an error).
[quoted text clipped - 68 lines]
>>>>>> the
>>>>>> AutoExec, but it may have be a failure of the ActivateEvents.
Tony Jollans - 17 Oct 2006 12:00 GMT
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.

--
Enjoy,
Tony

> Hi Tony,
>
[quoted text clipped - 126 lines]
> >> >>>>>>
> >> >>>>>> /e
Doug Robbins - Word MVP - 17 Oct 2006 18:42 GMT
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.

Signature

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

> Hi Doug,
>
[quoted text clipped - 158 lines]
>> >> >>>>>>
>> >> >>>>>> /e
Tony Jollans - 17 Oct 2006 22:09 GMT
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.

--
Enjoy,
Tony

> Hi Tony,
>
[quoted text clipped - 183 lines]
> >> >> >>>>>>
> >> >> >>>>>> /e

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.