title: Excel VBA: Disable Auto Open when Save As function is run
body: <p>I am running a code that takes the data that is input and creates a copy of the file. That is fine; however, the new file opens every time it is saved. I would like to save the file without it opening up automatically. I was playing around with some code, listed below: </p>
  
  <pre><code> Dim x As Object
          Set x = Application.VBE.ActiveVBProject.VBComponents
          x.Remove VBComponent:=x.Item("TestModule")
  </code></pre>
  
  <p>Below is the entirety of the code for the Save As function.</p>
  
  <pre><code>Public sourceWB As Workbook
  Public sourceWS As Worksheet
  Public targetWB As Workbook
  Public targetWS As Worksheet
  Public sDate As String
  
  Sub Main()
  
     sDate = Format(Now(), "mm.dd.yyyy")
      Set sourceWB = ThisWorkbook
      Set sourceWS = sourceWB.Sheets("**FILE NAME DISCREET")
  
  
      Set targetWB = Workbooks.Add
      Dim theFilename As String
     theFilename = "**FILE NAME DISCREET**" + sDate + ".xlsx"
  
     targetWB.SaveAs FileName:= **"FILE LOCATION TO BE KEPT DISCREET, SORRY "**
      Set targetWS = targetWB.Sheets("Sheet1")
  
     sourceWS.Range("A1:H45").Copy targetWS.Range("A1")
     targetWB.Save
  
  End Sub
  
  Private Sub ManhExportData_Click()
         Call Main
  End Sub
  </code></pre>