excelvbauserformself-executing-function

After a re-open function how can i get it to kick off my userform again?


So this function will effectively restart my workbook however, it is not kicking of my userform that i have set to open on workbook open and im not sure why. I dont know if it is bypassing that function or what...

Private Sub CommandButton3_Click()

Dim sPath As String
Dim sName As String
sName = ThisWorkbook.Name
sPath = ThisWorkbook.Path
ThisWorkbook.Saved = True
Workbooks.Open Filename:=sPath & "\" & sName

''''at a minimum I need this userform to show and it wont when i run this funtion.
UserForm1.Show

End Sub

Solution

  • You can't open the same file that you already have active. So you need to close it first to open it once again. It breaks your code. so it won't work. You need to close it.

    If you want to have your UserForm to pop up at start just put my code to Workbook_Open and it will be opend each time you start your file.

    Private Sub CommandButton3_Click()
    'Vbmodal ensures that user need to interact with userform or discard it to select cells etc.
    UserForm1.Show vbmodal
    
    End Sub