title: VBA - A document with the name '' is already open
body: <p>I have written a macro in Excel that I assigned to a button in a workbook. When pressed it asks a user for a file, opens that file and copies the contents into the sheet2 in the original workbook, then saves the original workbook under a new name. It then creates a new button on the worksheet to run another subroutine. When pressing the button a window pops up saying "A document with the name (document name) is already open. Is there anyway to resolve this? I assume this is happening because I'm saving the original workbook under a new name.</p>
  
  <pre><code>Sub openFile()
  
  Dim tempWB As Object, btn As Button, desktopPath As String
  
  fileToOpen = Application.GetOpenFilename(Title:="Select transaction history export:")
  If fileToOpen &lt;&gt; False Then
      Set tempWB = Workbooks.Open(Filename:=fileToOpen)
  End If
  If fileToOpen = False Then
      End
  End If
  
  ActiveSheet.Cells.Copy
  Workbooks("Test.xlsm").Sheets("Sheet2").Activate
  ActiveSheet.Cells.ClearContents
  ActiveSheet.Cells(1, 1).Select
  ActiveSheet.Paste
  tempWB.Close
  
  Set btn = ActiveSheet.Buttons.Add(650, 50, 100, 40)
  With btn
      .OnAction = "action"
  End With
  
  desktopPath = (MacScript("(path to desktop from user domain as string)") &amp; ":")
  
  ActiveWorkbook.SaveAs Filename:=(desktopPath &amp; "Result" &amp; VBA.format(Date, "mm/dd/yy") &amp; ".xlsm")
  
  End Sub
  
  Sub action()
  
  Range("A1:B1").Font.Size = 14
  
  End Sub
  </code></pre>