I'd like to show a UserForm, but allow the user to look through worksbooks and worksheets. I know I can hide the UF, but I'd prefer to leave up the UF. Is this possible? I know there's vbModeless
, but the code continues to execute, which is not what I want.
My code so far looks somewhat like this:
Sub Test()
Dim Counter As Long
Dim wb As Workbook
Application.ScreenUpdating = False
'-------main code
If Counter <> 0 Then
frmTest.Show
End If
Unload Me
For Each wb In Application.Workbooks
If wb.Name Like "Report*" Then wb.Close SaveChanges:=True
Next wb
Application.ScreenUpdating = True
End Sub
I could change the if-statement to
If ErrorCount > 0 Then
frmTest.Show vbModeless
Else
Call SaveWorkbooks
End If
Application.ScreenUpdating = True
End Sub
And create another sub:
Sub SaveWorkbooks()
Dim wb As Workbook
Unload frmTest
For Each wb In Application.Workbooks
If wb.Name Like "Report*" Then wb.Close SaveChanges:=True
Next wb
End Sub
I guess that works, but
- Is it good practice splitting up your code like that?
- What if this occurred in the middle of my main sub? That would make 1) even worse.
Is there a more elegant solution