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 2007

Tip: Looking for answers? Try searching our database.

Word Open event

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Doekoe - 18 Oct 2007 11:01 GMT
I want to have some code to run as Word (client opens Word) opens.
However I can not find the right Event. I thought it will do so at
Document_New(), but this event is happening when you hit the New Icon.

What event is happening as soon as Word opens?

Thanks,

Dirk
Jonathan West - 18 Oct 2007 11:20 GMT
>I want to have some code to run as Word (client opens Word) opens.
> However I can not find the right Event. I thought it will do so at
[quoted text clipped - 5 lines]
>
> Dirk

There is no such event. However, if you have an add-in, if you name a macro
"AutoExec" it will automatically run when the add-in is first loaded by
Word. If the add-in is placed in Word's Startup folder, it is automatically
loaded when Word is started.

Look up Auto Macros in the VBA help for more on this.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

Doekoe - 18 Oct 2007 13:17 GMT
> >I want to have some code to run as Word (client opens Word) opens.
> > However I can not find the right Event. I thought it will do so at
[quoted text clipped - 17 lines]
> Jonathan West - Word MVPwww.intelligentdocuments.co.uk
> Please reply to the newsgroup

Thanks for you answer, however can you tell mee what an add-in is and
how to make this?

Dirk
NNV - 18 Oct 2007 15:39 GMT
> > >I want to have some code to run as Word (client opens Word) opens.
> > > However I can not find the right Event. I thought it will do so at
[quoted text clipped - 22 lines]
>
> Dirk

You only use event  Document_Open()
Don't need to use add-in.
Doekoe - 19 Oct 2007 08:05 GMT
> > > "Doekoe" <d.schinge...@eromes.nl> wrote in message
>
[quoted text clipped - 31 lines]
>
> - Tekst uit oorspronkelijk bericht weergeven -

I know the Document_Open() event, this one I used and programmed,
however this is not run when Word starts. This events executes when
you open a Word Document. The same with the Document_New() event, this
event executes when you hit the new icon. I do not understand why the
Document_New() is not executed when Word starts up, because then Word
shows a new document.

Dirk
NNV - 19 Oct 2007 12:55 GMT
Signature

Coding...coding and coding

> > > > "Doekoe" <d.schinge...@eromes.nl> wrote in message
> >
[quoted text clipped - 40 lines]
>
> Dirk

Hi Doekoe, you must put Document_Open event in ThisDocument, not in Module.
In Microsoft Office Word, events only execute when are put in ThisDocument of
Project.
Please, let try this code in ThisDocument
 Sub Document_Open()
     MsgBox "Hello"
 End Sub

Good luck!!!!
Shauna Kelly - 20 Oct 2007 10:56 GMT
Hi NNV

Inline

Hope this helps.

Shauna Kelly.  Microsoft MVP.
http://www.shaunakelly.com/word

>> > > > "Doekoe" <d.schinge...@eromes.nl> wrote in message
>> >
[quoted text clipped - 46 lines]
>>
>> Dirk

> Hi Doekoe, you must put Document_Open event in ThisDocument, not in
> Module.
> In Microsoft Office Word, events only execute when are put in ThisDocument
> of
> Project.

That is correct. The Document_Open event runs from ThisDocument.

> Please, let try this code in ThisDocument
>  Sub Document_Open()
>      MsgBox "Hello"
>  End Sub
>
> Good luck!!!!

The Document_Open event will fire:
   - if the code is in a document, then when that document opens

   - if the code is in a template, then whenever any document based on that
template is opened

   - if the code is in an add-in, then whenever you do File > Open to open
the add-in. That does not happen in ordinary operations, so if there is
Document_Open code in an add-in, it effectively never fires.

If you put code for a Document_Open event in normal.dot, then it will fire
every time you create a new document based on normal.dot. It will not fire
whenever any new document is created, and it will not fire whenever Word
starts (not least because you might start Word without displaying a
document, or might tell Word to start with a new document based on a
specific template).
Doekoe - 24 Oct 2007 11:25 GMT
> Hi NNV
>
[quoted text clipped - 91 lines]
>
> - Tekst uit oorspronkelijk bericht weergeven -

Hi Shauna,

First off all thanks for your reply. I am busy to get things work, but
it will not happen. Here what I have done:

- I created a template and save it as 'dirk.dot' in C:\Documents and
Settings\d.schingenga\Application Data\Microsoft\Word\OPSTARTEN, as
adviced
- If I start MS Word and open the VBA Editor, it only shows Normal en
Project(Document1), so my template is not loaded I guess

The longer I am trying the more confused I get about how things work.
I would appreciate some more help, only thing I want is: every time a
user starts Word, some code is executed.

Dirk
Shauna Kelly - 25 Oct 2007 01:38 GMT
>> Hi NNV
>>
[quoted text clipped - 115 lines]
>
> Dirk

Hi Dirk

OK, let's go back to first principles. Since you said your startup folder
was named OPSTARTEN, I'm assuming you don't have an English language version
of Word, so you may have to translate the menu items.

First, do Tools > Options > Security. Click the Macro Security button.
You'll see the Security dialog. On the Trusted Publishers tab, tick the
button "Trust all installed add-ins and templates" and click OK, OK to get
back to Word.

Now, create a little test like this:

1. File > New. In the task pane, choose "On my computer". You'll see the
Templates dialog box. In the bottom right hand corner, choose to create a
new Template, and then click OK.

2. Word should have created "Template 1" or a name like that.

3. Alt-F11 to open up the VBE. In the project explorer list, click the item
with name of the template (eg "Template 1") and then do Insert > Module.

4. Paste the following into the code area

Public Sub AutoExec()

   MsgBox "This message is from " & ThisDocument.Name

End Sub

5. Close the VBE to get back to the template itself.

6. Tools > Options. On the File Locations tab, identify the location of the
Statup folder. Make sure it hasn't been changed somehow.

7. Save the template in your Word startup folder.

8. Exit Word and re-start Word.

9. Expect:
(a) to see the message box
(b) at Tools > Templates and Add-ins you can see your Add-in listed and
ticked.

OK?

Hope this helps.

Shauna Kelly.  Microsoft MVP.
http://www.shaunakelly.com/word
Doekoe - 25 Oct 2007 13:56 GMT
On 25 okt, 02:38, "Shauna Kelly"
<ShaunaKe...@SendNoSpamToShaunaKelly.com> wrote:

> >> Hi NNV
>
[quoted text clipped - 171 lines]
>
> - Tekst uit oorspronkelijk bericht weergeven -

Hi Shauna,

Thanks for your time to make the step by step manual. I run through
your steps and saw I already did it right. Only the AutoExec was on a
different location. However at first it also did not work, and now I
found out why. It is because Outlook is started. As soon as I close
Outlook, and starts Word it works fine. I get the message and also my
own code was executed.

Now I am wondering how to get this work past Outlook, because Outlook
is always run at our clients. Two questions left:

1. How do I get it work even if Outlook is running (I use Word as my
text Editor in Outlook, if I schwitch this off, it works fine)

2. If I open Word and go to VBA, my own Template is locked (not able
to change something), but the 'Normal' template is editable. Why is
that?

Regards,

Dirk
Jonathan West - 30 Oct 2007 11:53 GMT
> Hi Shauna,
>
[quoted text clipped - 10 lines]
> 1. How do I get it work even if Outlook is running (I use Word as my
> text Editor in Outlook, if I switch this off, it works fine)

This has been the cause of a lot of problems. The simplest approach is to
have your Autoexec macro set a flag when it has completed its initialisation
work. Every other macro in the add-in should start out by checking the flag.
If it hasn't been set, then run Autoexec before proceeding. AutoExec is not
run on loading if the first use of Word in a session is to edit an email,
but at least it gets run before any other macro gets going.

> 2. If I open Word and go to VBA, my own Template is locked (not able
> to change something), but the 'Normal' template is editable. Why is
> that?

In order to edit macros in your add-in, you have to have the file open in a
document editing window.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

Shauna Kelly - 20 Oct 2007 10:46 GMT
Hi Dirk

An add-in is created in the same way as a template (File > New; create a new
Template). But do *not* save it in the UserTemplates folder. Instead, either
save it anywhere and load it through Tools > Templates and Add-ins. Or, more
usually, save it in the folder that Word designates as the Startup folder at
Tools > Options > File Locations.

For further information see
What do Templates and Add-ins store?
http://www.word.mvps.org/FAQs/Customization/WhatTemplatesStore.htm

Hope this helps.

Shauna Kelly.  Microsoft MVP.
http://www.shaunakelly.com/word

>> >I want to have some code to run as Word (client opens Word) opens.
>> > However I can not find the right Event. I thought it will do so at
[quoted text clipped - 24 lines]
>
> Dirk

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.