I have written the following vba macro to save a particular worksheet as a separate workbook.
Private Sub ExportRptCommandButton_Cli
ck()
Dim fName As String, FileNm As String
'GET THE NEW FILENAME FROM THE CURRENT SHEET
FileNm = ActiveSheet.Range("H1").Va
lue & ActiveSheet.Range("I1").Va
lue
fName = ActiveWorkbook.Path & "\" & FileNm & ".xls"
Debug.Print fName
'IF THE FILE ALREADY EXISTS THEN DELETE IT --------------------------
-------*
If Dir(fName) <> "" Then Kill fName
'COPY THE WORKSHEET
ThisWorkbook.ActiveSheet.C
opy
'SAVE THE NEW WORKBOOK
ActiveWorkbook.SaveAs Filename:=fName
ActiveWorkbook.Close
End Sub
It works just fine EXCEPT that after I do this - when I try and close the original workbook I get the following error
"This workbook is currently referenced by another workbook and cannot be closed." I hit OK and it closes anyway.
What is happening and how do I fix this. This stupid project is due today and that is the only annoying bug I have left.
Thank you,
Start Free Trial