Share via

Disabling a UserForm after first save

Anonymous
2019-01-15T19:07:48+00:00

What code would I need to write in order to prevent my UserForm from automatically opening after a document is saved for the first time?

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2019-01-15T19:49:25+00:00

Try

Private Sub Document_New()
  Dim oFrm As UserForm1
  Set oFrm = New UserForm1
  oFrm.Show
  Unload oFrm
  Set oFrm = Nothing
lbl_Exit:
  Exit Sub
End Sub

This goes in the ThisDocument part of the template's code. It will only run when a new document is created based on the template.  It is technically better than simply showing because it releases memory. Probably not a big deal. The big deal is the Document_New rather than Document_Open.

I would also use something more descriptive for your form's name like

frmStartList 

If you do this very much, you are going to want to try to name your projects, modules and forms so that they have a chance of having unique meaningful names.

Here are a couple of my Add-Ins that use UserForms. You are welcome to look at the code.

I am not a programmer, I am a lawyer who dabbles.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2019-01-15T20:16:12+00:00

    Thank you so much!

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2019-01-15T19:35:35+00:00

    I understand that, but I am new to this so I don't know where to start. 

    I went through your websites but couldn't seem to figure it out.

    Here is the code I have written to open the userform when the document is opened: 

    Private Sub Document_Open()

        UserForm1.Show

    End Sub

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2019-01-15T19:10:02+00:00

    Hi,

    You would use an AutoNew macro to show your form. This would be in the template. That launches the UserForm. It will only run when a new document is created.

    Create a Simple Userform by Graham Mayor, MVP

    http://www.gmayor.com/Userform.htm

    Create & Employ a Userform by Greg Maxey, MVP

    http://gregmaxey.com/word_tip_pages/create_empl...

    This is a user-to-user support forum. I am a fellow user. I hope this information helps.

    You are asked below whether this response solved your problem, please do not answer that question for this or any response unless the answer is "yes" or unless you feel that the response is not helpful to you in resolving your problem. Otherwise it reports the response as not being helpful. A "no" answer on any response will not give you any more help than not answering but will give negative reinforcement to the person who responded. On the other hand, a "yes" answer to that question helps other users with the same or a similar question by directing them to the response.

    What can help you get more help is providing more information or examples about the problem you are facing. You can do that by replying to this post. Please let me know if you have any more questions or require further help.

    Regards

    Was this answer helpful?

    0 comments No comments