Results 1 to 2 of 2

Thread: Show userform with macro

  1. #1

    Show userform with macro

    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".

    Udklip.jpg

    Regards

    Kristoffer

  2. #2
    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.

    form1.jpg

    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
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •