Below is the entire code i have.
It is supposed to copy the open active workbook and saveas in a different location. While doing so i want some sheets to be deleted according to value chosen in combobox3. Everything works but it wont delete that sheet while creating the new workbook. It does delete it, but then it gets created again . I think i know this is happening because when i got rid of the Application.Displayalerts, diaglog box asked to confirm the delete and it deleted the sheet for a second but it recreated it
Private Sub CommandButton1_Click()
Dim newWBK As Workbook
'Grab Data From UserFrom
MyProduct = UserForm1.ComboBox1.Value
MyApplication = UserForm1.ComboBox2.Value
MySCN = UserForm1.TextBox1.Value
MyEvent = UserForm1.TextBox2.Value
MsgProceed = MsgBox("File Name : " & MyProduct & "-" & MyApplication & "-" & MySCN & "-" & MyEvent, vbYesNo, "Create New Submission?")
If MsgProceed = vbNo Then Exit Sub
Unload UserForm1
UserForm1.Hide
Dim vFilename As Variant
Dim vPath As Variant
vpath1 = "\\tarcds01\eCTD_Submission\TRACKERS\" & MyProduct & "\" & MyApplication & "\"
vpath2 = MyProduct & "-" & MyApplication & "-" & MySCN & "-" & MyEvent
ActiveWorkbook.SaveCopyAs Filename:=vpath1 & vpath2 & ".xlsm"
'name new WB
Set newWBK = Workbooks.Open(vpath1 & vpath2 & ".xlsm")
'Make the new workbook active
newWBK.Activate
Application.DisplayAlerts = False
If ComboBox3.Value = "Master" Then
Sheet7.Delete
End If
Application.DisplayAlerts = True
ActiveSheet.Range("Q1").Value = MyProduct
ActiveSheet.Range("R1").Value = MyApplication
ActiveSheet.Range("S1").Value = MySCN
ActiveSheet.Range("T1").Value = MyEvent
FriendlyName1 = "Link to Documents with SCN"
MyPath1 = "https://tarregsp01p/sites/Regulatory/NextDocs%20Document%20Library/Forms/Detailed%20View.aspx?View={0C67A7C1-5BDA-4B11-A42D-4064D61BF7EC}&FilterField1=SCNNumber&FilterValue1=" & MySCN
FriendlyName1 = "Link to RegApp with product"
MyPath2 = "https://tarregsp01p/sites/Regulatory/_layouts/FormServer.aspx?XmlLocation=/sites/Regulatory/RegApp/Submission/Submission-" & MyProduct & "-" & MySCN & ".xml&DefaultItemOpen=1"
ActiveSheet.Range("A1").Formula = "=Hyperlink(""" & MyPath1 & """, """ & "Link to Documents with - " & MySCN & """)"
ActiveSheet.Range("C1").Formula = "=Hyperlink(""" & MyPath2 & """, """ & "Link to RegApp for - " & MySCN & " " & MyEvent & """)"
newWBK.Save
newWBK.Activate
'Close the template without saving
ThisWorkbook.Close False
End Sub
Bookmarks