save as macro

K

KJ

Here is a macro I created. Run I run the macro it creates the new file with
the correct filename in the correct location. However I still have the
previous (Book1) file open.
What I want is to close Book1 without saving.

Any help would be greatly appreciated.
Thanks, Ken.

Sub copyws()
Dim strName As String
Dim ws As Worksheet
strName = "C:\Documents and Settings\Ken1\My Documents\Quotes\" &
Range("A1").Value
Set ws = ThisWorkbook.Sheets(1)
Application.Workbooks.Add
ws.Copy before:=ActiveWorkbook.Sheets(1)
ActiveWorkbook.SaveAs strName

Set ws = Nothing

End Sub
 
F

FSt1

hi
can't do that. small technicallity. a macro must finish before the file can
be closed and a macro cannot close the file it resides in.
sorry
regards
FSt1
 
D

Dave Peterson

Book1 is the workbook that contains the macro?

If yes, then just add:

thisworkbook.close savechanges:=false 'or True

right before the "End Sub" line.
 

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