ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   save as macro (https://www.excelbanter.com/excel-discussion-misc-queries/179144-save-macro.html)

KJ

save as macro
 
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 befo=ActiveWorkbook.Sheets(1)
ActiveWorkbook.SaveAs strName

Set ws = Nothing

End Sub


FSt1

save as macro
 
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

"KJ" wrote:

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 befo=ActiveWorkbook.Sheets(1)
ActiveWorkbook.SaveAs strName

Set ws = Nothing

End Sub


Dave Peterson

save as macro
 
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.


KJ wrote:

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 befo=ActiveWorkbook.Sheets(1)
ActiveWorkbook.SaveAs strName

Set ws = Nothing

End Sub


--

Dave Peterson


All times are GMT +1. The time now is 03:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com