Closing an inactive workbook

M

Michael Wise

I have 2 files. One is initially run to save some
changes. Upon the click it saves these changes to a file
called WoNumbers.csv and then proceeds to open the next
file and auto run its macro's. The problem i'm having is
how to close the initial save as file created. Because at
the end of the second file run its procedure is to kill
this WoNumbers.csv created but its still open. I have
pasted the code below for the initial file.

Michael

Private Sub CommandButton1_Click()
ActiveWorkbook.SaveAs Filename:="C:\Psv
travelog\WoNumbers.csv", FileFormat:=xlCSV
'
'
Workbooks.Open ("C:\PSV travelog\PSV WO and
Specs.xls"), ReadOnly:=True
Workbooks("WoNumbers.csv").Close
ActiveWorkbook.RunAutoMacros xlAutoOpen

End Sub
 
M

Michael Wise

Thanks Tom,

Yes it does close the file but my code in the second file will not aut
run. If I move the auto open statment before close then this workboo
is no longer active. I need for the code to auto run when opened in th
second file
 
T

Tom Ogilvy

Private Sub CommandButton1_Click()
Dim wkbk as Workbook
ActiveWorkbook.SaveAs Filename:="C:\Psv
travelog\WoNumbers.csv", FileFormat:=xlCSV
'
'
Set wkbk = Workbooks.Open ( _
"C:\PSV travelog\PSV WO and Specs.xls"), ReadOnly:=True
Workbooks("WoNumbers.csv").Close
wkbk.RunAutoMacros xlAutoOpen

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top