View Full Version : macro
I have created a template out of Word. I then went into Visual basic Editor to create a dialog prompt box(User Form) so the user can input values into the Word template. I have tested and ran the VBE Form, I now just need to know how to make that Dialog prompt box that was made from VBE to automatically load when you open the Word Template.
I hope I was clear enough
Let assume that the dialog box you’ve created is called from a sub called MyDialog ().
Go to the vb editor, make sure that the Project Explorer is open “it’s the little window on the left that’s titled ‘Project – Project’” if it’s not, then, click View, Project Explorer or Control + R.
Look in the Project Explorer, you’ll see the objects and containers in word, the first one is called “Normal”, unless you want a global macro that will run every time word is opened, you don’t want to touch this. Expand the one that’s titled “Project (xxx)” where xxx is the name of your saved document. Expand the Microsoft Word Object folder. Here you’ll find a container called ThisDocument double click it.
On the right, choose Document from the object drop-down list. The valid events for the Document object are listed in the Procedure drop-down list box “On the right”. Select an event from the Procedure drop-down list box; an empty procedure is added to the class module. The event you want is the Open event, select it and you’ll have a “Document_Open()”sub procedure created for you. Place one line of code that will call your dialog box procedure, like;
Call MyDialog
Next time this document is opened, word would look in the “Document_Open()” sub procedure and execute any code there.
Good luck
Jama
<a target="_blank" href=http://www.jama.x5g.com> What do you think? </a>
How do you call the dialog box(The Form that I made) from a Sub?? I think thats what I am stuck on.
Forget about the sub, just copy this 2 lines to “Private Sub Document_Open()” in your project;
Load frmFileRequest
frmFileRequest.Show
Jama
<a target="_blank" href=http://www.jama.x5g.com> Do you like my penguin? </a>
Yes your penguin is very nice.
Okay The macro is running fine now. But I have another problem, When I try to save it as a template(*.dot) It does not seem to want to the macro. It opens the template fine though.
I found out I have to open the template itself, for example. I would have to right click the icon and chose open for the macro to show up. But if I were to double click it just opens up a new document and with template form and no macro is ran.
Can someone please help me.
Right click the template and choose open. Your macro should run, just close the form and open the vbeditor. In the explorer pan expand the tree named TemplateProject(XXX), expand Microsoft Word Objects and double click ThisDocument.
On the right you’ll see this;
Private Sub Document_Open()
Load frmFileRequest
frmFileRequest.Show
End Sub
Change the Private Sub Document_Open() to Private Sub Document_New() so it should look like this;
Private Sub Document_New()
frmFileRequest.Show
End Sub
You don’t really need “Load frmFileRequest”.
In vbeditor, click file then “save XXX”.
Next time you create a new document based on this template, your macro will run!. "i hope"
Take it easy on me, everyone makes mistakes!
Jama
Powered by vBulletin™ Version 4.1.0 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.