Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Closed Thread
LinkBack Thread Tools Display Modes
Old 09-26-2017, 04:31 AM
ShogunPatch ShogunPatch is offline Windows 10 Office 2016
Join Date: Sep 2017
Posts: 1
ShogunPatch is on a distinguished road
Default Calling up a userform whenever a new document is created

Greetings all.

I'm new to this forum and pretty new to Word macro programming to please bear with me...

I have developed a custom macro-enabled building blocks template ("MyBuildingBlocks") which, in addition to various standard document components, includes a number of userforms which are designed to guide the user to insert the correct building block to start his document with;
  • The primary form ("frmTemplateOptions") asks users to select a category of document using radio buttons. Then depending on the option chosen;
  • The correct one of a choice of secondary userforms ("frmOptionA", "frmOptionB", "frmOptionC", etc) is called up asking users to select a specific document from within the selected type, again using buttons;
  • Finally, the relevant building block is inserted according to the selection made.

Referring to various articles online, I have created a macro ("CallUF_TemplateOptions") within a module ("modTemplateOptions") in MyBuildingBlocks with which I can successfully call up the primary userform. This then correctly takes me through my selection options and inserts the required building block.

If I start Word and manually call up the primary userform using this macro, everything seems to work fine. My problem is that I want the primary userform to flash up automatically every time I create a new document (i.e. open word for the first time as it is set to open a new doc automatically, or press Ctrl +N, click on the New Document icon on the QAT, etc). I do not want it to come up if I open up an existing document (either when I chose file/open from within word, or if I right-click on the Word icon in the start bar and then choose an existing document).

I've managed to get halfway there by adding some code to a public AutoExec sub in a second module ("modLaunchPrimaryForm"). This successfully calls up the form when I first open word, but:
  • If I create another new document from within Word it does not launch
  • If I open an existing document it launches and I have to cancel before the exisitng document opens up

I suspect this is really simple if you know what you're doing - which I clearly don't - so any pointers to help me get on the right track would be much appreciated.
Old 09-26-2017, 08:00 AM
slaycock slaycock is offline Windows 7 64bit Office 2013
Competent Performer
Join Date: Sep 2013
Posts: 226
slaycock is on a distinguished road

Is your new document based on the same template as the first. The template is the document that holds the code. If your new document is not based on the same template then there won't be any code to call.

You should also have a look at AutoOpen.
Old 09-26-2017, 09:24 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 17,800
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold

Cross-posted (and answered before posting here) at:
For cross-posting etiquette, please read:

Thread closed.
Paul Edstein
[MS MVP - Word]
Closed Thread

autoexec, userform

Thread Tools
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
export UserForm created strings to generated Document from template Trainee Word VBA 2 09-13-2017 02:29 AM
Calling Sub Routine for Formatting recently Created Word Document rpb925 Word VBA 12 03-31-2016 03:14 AM
Adding tables to Created word document whilst other word document open Help rpb925 Word VBA 18 03-30-2016 04:45 PM
Insert an image to a document created by a userform? jgoodrich Word VBA 0 10-22-2014 11:03 AM
Is it possible to take an input from a UserForm in one document to a UserForm in a do BoringDavid Word VBA 5 05-09-2014 09:08 AM

All times are GMT -7. The time now is 08:57 PM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc. is not affiliated with Microsoft