![]() |
#1
|
|||
|
|||
![]() Help friends... I figured out how to create a macro to have an informational message box pop up when you open up my word doc, however this particular doc is a template, and so it only works when you right click and choose open, vs if you were to double click to open up the actual template like normal, of which I have multiple boxes pop up to automatically fill in fields throughout the document. (Probably confusing)... So my question is, how do I get an auto message to pop up on a template document BEFORE the auto field questions come up on a normal double click to open the doc? ![]() |
#2
|
|||
|
|||
![]()
Hi
Sounds like you need an AutoExec Macro not an AutoOpen. AutoExec macros run before a document is opened whereas AutoOpen runs when a document is opened. Have a look at this link: http://support.microsoft.com/kb/286310 Good luck. Tony |
#3
|
|||
|
|||
![]()
Oh ok I hear ya. So I had this:
'-------- AUTOOPEN --------------- Sub AutoOpen() 'runs when document is opened 'This name "AutoOpen" is a Visual Basic reserved name for launching 'code when a Word document is opened. 'AutoOpen works in Word 'Auto_Open works in Excel MsgBox "Ensure that you get Manager authorization", vbOKOnly + vbInformation, "NOTE" End Sub Do you have any idea how I edit all that to what I need? |
#4
|
|||
|
|||
![]()
Hi Drizz
Sorry for the late response as I have ben offline for a few days. I will have a look at your issue today and get back to you. Tony |
#5
|
|||
|
|||
![]()
Hi Drizz
Follow these steps: 1. Open your Normal.dotm template (NOT a document). 2. Create a Macro in a Module as follows: Sub AutoExec() 'runs when document is opened 'This name "AutoExec" is a Visual Basic reserved name for launching 'code when a Word is opened. MsgBox "Ensure that you get Manager authorization", vbOKOnly + vbInformation, "NOTE" End Sub 3. Save your template and close it. 4. Open Word in the normal manner and the AutoExec Macro will run BEFORE any document is opened. Bear in mind that this will only work on your version of the Normal.dotm template if it is stored locally. If you are using a networked version of the Template then create the macro in that copy of the template. If you want it to work on multiple machines then you must do the same for each machine. Good luck. Come back to the forum if you need further help. Good luck. Tony Last edited by OTPM; 04-23-2013 at 06:47 AM. |
#6
|
|||
|
|||
![]()
I am a little confused. Are you USING the template to create a new document? If you are, then a message in Document_New will fire before any field questions.
"come up on a normal double click to open the doc" A double click does NOT open a template file. |
#7
|
|||
|
|||
![]()
Tony, that actually worked great until I realized it made it to where when I opened even a blank doc it would pop up, vs just for that template. I looked and saw that when I create the macro, I can choose "all documents and templates" or just my current template, but when I choose that option, it doesn't work at all. From what I can tell this is a .dotx template
Fumei, this is a template that has fields pop up to fill out and then when you are finished, it creates a new document for you to save where you want it. I'm not sure what you mean by "then a message in Document_New"... ??? |
#8
|
|||
|
|||
![]()
Please describe EXACTLY the steps that happen.
Are you saying you double click on a template, you get a userform with fields to fill in...and THEN a new document is created. If you have ANY action happening before a document is visibly created then that code is in Document_New. That is, if the code is in the template. It seems that there is a bit of confusion between code in Normal, and code that may be in the template. BTW: you definitely are actioning code that is in Normal if the actions occur with all documents. |
#9
|
|||
|
|||
![]() Quote:
Document_New is the vehicle by which a template (a dotm) performs actions before presenting a newly created document. That most definitely includes giving the user fields to fill out. Then, when the user is finished, the new document is presented with (I assume) the data from the filled in fields. IMO, it is rare that AutoOpen, or AutoNew, or even AutoExec are the way to go. That is very old school. |
#10
|
|||
|
|||
![]()
Hi fumei,
I don't have anyone right click to open the template, as obviously that defeats the purpose. I only meant to say that it only worked when I did that and was why I needed autoexec vs autoopen. Anyhow, this is a template that someone would double click on (or in this case single click, as there is a link on our intranet that they click and a dialog box prompts them to open the template). Then, a field window pops up where they enter information, they click ok, then another field pops up where they enter more, etc etc for several pieces of information that fill in throughout the document, then they can save the new doc anywhere (so yes, it creates a new doc) I am needing a message box to pop up when they open the template and BEFORE the fields pop up because if they don't meet the requirements in the message box, they are advised to not use the template at all. P.S. I am VERY green at this side of word, so don't be afraid to speak in stupid people terms and tell me what to do step by step ;-) That being said, is there a problem that this is saving as a dotx vs dotm? I don't know what's new/old as I never use macros etc etc so talk dumb and if nothing can be done, let me know. |
#11
|
|||
|
|||
![]()
I will say it again, they are not opening the template. They are (at least I think that is what you are saying) calling the template.
I have no idea what you mean by "field window". A userform is a separate kind-of dialog that is used to gather user information. " why I needed autoexec vs autoopen. " I do not think you need either. "they are advised to not use the template at all." So they start to use the template...and then are frozen out of it? Fair enough, but you still do not need AutoExec, or AutoOpen. What are the requirements (and how are these determined) that decide whether to proceed further? In any case, here is a simple example of what I am talking about. You have a dot file (the template). It has however many userforms you need (for the fields to be filled in). The FIRST userform is the one that decides to go further, or not. In the ThisDocument module, on Dpcument_New - the template is called, the first userform is shown. Code:
Option Explicit Private Sub Document_New() UserForm1.Show End Sub Code:
Option Explicit Private Sub CommandButton1_Click() If TextBox1.Text <> "yadda" Then Msgbox "Requirements not met. Template will close." ActiveDocument.Close Unload Me Else ' show the other "fields" End If End Sub That means, if the requirement is not met (in this case the text is not "yadda"), there is a message stating requirements not met, the new document closes (never actually shown), the userform closes...and things stop. If the requirements ARE met - the Else of the IF statement - you proceed with the other field fillin stuff in the other userforms. No AutoExec. No AutoOpen. |
#12
|
|||
|
|||
![]()
You want an AutoNew macro in the template or Document_New.
AutoOpen - fires when the file holding the macro is opened. AutoExec - fires when the file holding the macro is loaded as a global template or Add-In. AutoNew - fires when a new document is created based on the template. Note if you put an AutoNew or AutoOpen or Document_New or Document_Open procedure in a global template, including normal.dotm, it will act in all documents and templates! |
#13
|
|||
|
|||
![]()
Hi Drizz
What you need to do is ceate a specific template and follow the instructions I gave you. This will then only apply to documents created to that specific template. Hope that helps. Tony |
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Message from template not saving | nigh | Outlook | 0 | 01-11-2012 03:11 AM |
![]() |
Emerogork | Outlook | 2 | 09-06-2011 06:35 PM |
30 seconds to open an e-mail message | Emerogork | Office | 0 | 07-21-2011 08:49 AM |
Pop Up Message on Open | Emma Samm | Word | 0 | 12-20-2010 02:38 PM |
Can't Copy and Paste until new message is open | tabletop | Outlook | 0 | 12-04-2009 11:38 AM |