PDA

View Full Version : Show userform with macro



Kristoffer
12-20-2017, 02:15 AM
Hi

I have a new question: I have made a userform, which I would like to activate with a button in the Quick Launch bar, but I can't get the macro to show the userform to work.

The "Dokument1" is a Word-template, which I plan to rename to Normal.dotm, so it opens each time I open Word.

So far I have this: (Google has advised me that it should work, but I keep getting a "Run-time error 424. Object required".

21222

Regards

Kristoffer

gmayor
12-20-2017, 04:50 AM
No! You cannot create a normal.dotm file in this manner. Only Word can create a normal template.

You can either add the code and userform to the existing normal template or you can create a global template (saved in the Word startup folder) with the code and form and that will load with Word

If you have not changed the preferred startup folder it can be located (in English language versions of Windows) by typing
%appdata%\Microsoft\Word\Startup
in the Windows File Explorer Address bar and pressing Enter.

The reason for the error is that you have created the macro in the 'userform' module of the normal template project when the userform you are attempting to call is in the Document project. You should add an ordinary module to the DOCUMENT project and put the code to show the form in that module and remove it from the normal template. Conversely you could move the userform from the document project to the NORMAL project.

21224

I would also suggest calling the macro something other than Show, which is a vba command name and which may cause some confusion e.g.


Option Explicit

Sub Show_Form()
UserForm1.Show
End Sub