title: How to save the excel file with vba coding without opening it?
body: <p>I have added a button in excel sheet and added following codes in vba window of that button. Now when I click this button i.e. when I run the codes it saves the excel sheet in pdf form whose name it takes from cell no H8 and saves it at M:\formats. Moreover it also saves the same excel sheet in .xlsx format at M:\formats\excels. But here the problem is when I run the codes it closes the excel sheet in which I have added the codes and opens the file which is saved by the codes. For example I made abc.xlsm excel sheet and added the codes in vb window, now xyz is written in cell no h8 in abc.xlsm excel sheet, now when I will run the codes it closes abc.xlsm and all codes are shown in xyz.xlsx excel sheet. I want it should only save the file in xlsx format it requisite location. It should not close the base file (which is abc.xlsx in the above example) and should not open the saved file (which is xyz.xlsx in the above example). Moreover I want that the saved file (xyz.xlsx in the above example) should not contain any vba coding. In another words it should be just like the backup copy for the base file (which is abc.xlsx in the above example). Kindly help me in to modify these codes to them as I want. I will be highly obliged to you. Thanks </p>
  
  <pre><code>Sub ExportAPDF_and_SaveAsXLSX()
  
  Dim wsThisWorkSheet As Worksheet
  Dim objFileSystemObject As New Scripting.FileSystemObject
  
  Dim strFileName As String
  Dim strBasePath As String
  
  strBasePath = "M:\formats\"
  strFileName = Range("H8")
  
  On Error GoTo errHandler
  
  Set wsThisWorkSheet = ActiveSheet
  
  wsThisWorkSheet.ExportAsFixedFormat _
      Type:=xlTypePDF, _
      Filename:=strBasePath &amp; strFileName, _
      Quality:=xlQualityStandard, _
      IncludeDocProperties:=True, _
      IgnorePrintAreas:=False, _
      OpenAfterPublish:=False
  
  MsgBox "PDF file has been created."
  strBasePath = "M:\formats\excels\"
  strFileName = Range("H8")
  
  Application.DisplayAlerts = False
  
  strFileName = objFileSystemObject.GetBaseName(strFileName) &amp; ".xlsx"
  
  wsThisWorkSheet.SaveAs Filename:=strBasePath &amp; strFileName, 
  
  FileFormat:=xlOpenXMLWorkbook
  
  Application.DisplayAlerts = False
  
  MsgBox "Workbook now saved in XLSX format."
  
  
      exitHandler:
      Exit Sub
      errHandler:
      MsgBox "Could not create PDF file"
      Resume exitHandler
  
      End Sub
  </code></pre>