Please take a look at this code. I have a save button on my form that triggers this code to save a copy of the worksheet. I think the problem I'm having is that it creates another instance of Excel. That is, when I look at Windows Task Manager, I see two Excel applications running (and sometimes more than one). And, at some point, Excel hangs and I have to terminate the process. Is there something else I need to do here?
Code:
Private Sub CommandButton2_Click()
Dim wsName As String
Dim Wksname$
Dim str, strLast, strFirst As String
Dim r As Range
Dim savewks$
If TextBox2.Value <> "" Then
str = Split(TextBox2.Value, ",")
strLast = str(0)
strFirst = str(1)
Else
MsgBox "There is no data to be saved.",
Exit Sub
End If
Wksname = ActiveSheet.Name
On Error Resume Next
UnProtectSheet (Wksname$)
Sheets("sheet1").Copy before:=Sheets(9)
ActiveSheet.Shapes("CommandButton2").Select
Selection.Delete
savewks$ = ActiveSheet.Name
Call clearFormfields
Sheets(savewks$).Activate
ProtectSheet(Wksname$)
End Sub