Forum Discussion

tim_p70f9's avatar
tim_p70f9
Copper Contributor
Mar 24, 2020

excel userform close error

Hi all,

 

I have a user form that is called from the ThisWorkbook Module to run on startup the form works perfectaly until i try to close the form after the task is complete ive tried

Both Unload Me and Me.Hide oth of them throw an error

Runtime error 9 subscript out of range

 

Range("q14").Value = TextBox1.Text
Range("q11").Value = TextBox2.Text
Range("q12").Value = TextBox3.Text
Range("q15").Value = TextBox4.Text
Range("q13").Value = TextBox5.Text
Range("q16").Value = TextBox6.Text
Me.Hide ------- Here is when the error happens if i comment it out i get no error but the userform doesnt automaticaly close

ive also tried

Unload Me

 but again the same error

 

the form is called using the following from the this.workbook module

Dim form As New UserForm1
form.Show

 

 

3 Replies

  • tim_p70f9 

    Which event you are utilizing on ThisWorkbook Module? Is it Workbook_Open event?

    If yes, try to utilize Workbook_Activate event instead.

     

    Also, if you want to close the UserForm, use Unload instead of Hide as Hide will not close the UserForm but hide it i.e. make it invisible and the UserForm will still be available in the memory.

Resources