title: Excel Save As PDF And Overwrite Existing
body: <p>Here is the Problem I have encountered.</p>
  
  <p>I have created a Excel Project. At a point in my project I save the current workbook as a PDF and update a existing workbook with log information and hyperlink to the PDF (<strong>Step1</strong>).  </p>
  
  <p>At another point in the project I re-save the project as the same PDF (to Overwrite Existing PDF). At the point I try to re-save the PDF I receive:</p>
  
  <blockquote>
    <p>run-time error-1004 </p>
  </blockquote>
  
  <p>Document is not saved, may be opened or error may have been encountered. Here is the 2 scripts I use. </p>
  
  <p>I think maybe it might have something to do with the second part of <strong>step1</strong> script (when opening a workbook and updating log info, that it may not be closing properly)</p>
  
  <p>Please any help would be greatly appreciated, as I will continue to trouble shoot.</p>
  
  <p><strong>Step1:</strong></p>
  
  <pre><code>Sub Step1()
  Dim rng As Range
  Dim nwb As Workbook
  Dim FileName As String
  Dim var
  Dim var1
  Dim var2
  Dim var3
  Dim var4
  Dim var5
  Dim var6
  var1 = frmsetup.cmbauditor.Text
  var2 = frmsetup.lblsequence.Caption
  var3 = frmsetup.cmbtrimstyle.Text
  var = "SEQ-" &amp; frmsetup.lblsequence.Caption &amp; " "
  var4 = frmsetup.lbldate.Caption
  FileName = var &amp; var4
  
  With Sheets(Array("END RESULTS", "DRIVER SEAT", "PASSENGER SEAT", "40% SEAT", "60% SEAT", "RSC SEAT")).Select
  ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
      "H:\APPLICATIONS\SEAT AUDIT\QUERY RESULTS\SEAT AUDIT - PDF\" &amp; FileName &amp; ".pdf", Quality:=xlQualityStandard, _
      IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
      False
  End With
  Application.ScreenUpdating = False
  Application.WindowState = xlMaximized
  </code></pre>
  
  <p>This is the next part of the <strong>step1</strong>, it opens a existing workbook and adds log information including hyperlink to pdf:</p>
  
  <pre><code>Set nwb = Workbooks.Open("H:\APPLICATIONS\SEAT AUDIT\LOG FILES\Seat Audit Log.xlsm")
  With Sheets("Seat Audit Log")
  nextrow = Range("B" &amp; Rows.Count).End(xlUp).Row + 1
  Cells(nextrow, 1).Value = var1
  Cells(nextrow, 2).Value = var2
  Cells(nextrow, 3).Value = var3
  Cells(nextrow, 4).Value = var4
  Set rng = .Range("E" &amp; nextrow)
  rng.Parent.Hyperlinks.Add Anchor:=rng, Address:="H:\APPLICATIONS\SEAT AUDIT\QUERY RESULTS\SEAT AUDIT - PDF\" &amp; FileName &amp; ".pdf", TextToDisplay:="CLICK HERE!"
  End With
  Application.ScreenUpdating = True
  ActiveWorkbook.Save
  ActiveWindow.Close
  End Sub
  </code></pre>
  
  <p>This is the <strong>Step2</strong> re-save as PDF to overwrite existing PDF from Step1:</p>
  
  <pre><code>Sub Step2()
  Dim FileName As String
  Dim var
  Dim var4
  var = "SEQ-" &amp; frmsetup.lblsequence.Caption &amp; " "
  var4 = frmsetup.lbldate.Caption
  FileName = var &amp; var4
  
  With Sheets(Array("END RESULTS", "DRIVER SEAT", "PASSENGER SEAT", "40% SEAT", "60% SEAT", "RSC SEAT", "ACTIONS")).Select
  ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
      "H:\APPLICATIONS\SEAT AUDIT\QUERY RESULTS\SEAT AUDIT - PDF\" &amp; FileName &amp; ".pdf", Quality:=xlQualityStandard, _
      IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
      False
  End With
  
  End Sub
  </code></pre>