![]() |
Saving a workbook step in a Macro
I created a simple formatting macro and included the "save As" in the macro,
of course it wants to save the workbook as the name indicated in the macro. Can I have the macro save the workbook as the current workbook name? |
Saving a workbook step in a Macro
Are you saving the workbook with the code?
Do you want to overwrite the existing workbook? If yes to both, you can use: thisworkbook.save If you want to save a different workbook with the same name as the workbook that's running the code, then nope--you can't use Save|As. You can only have one file open with any particular name. There may be other work arounds. You could save the file with a temporary name. Close that file. And then use the Name statement to rename it to what you want. There are other things to consider, too. Is the workbook opened readonly? Are you trying to use the same drive/path/filename or what???? Mark wrote: I created a simple formatting macro and included the "save As" in the macro, of course it wants to save the workbook as the name indicated in the macro. Can I have the macro save the workbook as the current workbook name? -- Dave Peterson |
Saving a workbook step in a Macro
The file is originally a .csv file that i am formatting and then saving as an
..xls file using the same file name, in the same folder and directory. "Dave Peterson" wrote: Are you saving the workbook with the code? Do you want to overwrite the existing workbook? If yes to both, you can use: thisworkbook.save If you want to save a different workbook with the same name as the workbook that's running the code, then nope--you can't use Save|As. You can only have one file open with any particular name. There may be other work arounds. You could save the file with a temporary name. Close that file. And then use the Name statement to rename it to what you want. There are other things to consider, too. Is the workbook opened readonly? Are you trying to use the same drive/path/filename or what???? Mark wrote: I created a simple formatting macro and included the "save As" in the macro, of course it wants to save the workbook as the name indicated in the macro. Can I have the macro save the workbook as the current workbook name? -- Dave Peterson |
Saving a workbook step in a Macro
Note quite the same name (the extensions are different). So it's not a problem.
Option Explicit Sub testme() Dim myFileName As String With ActiveWorkbook 'strip off the extension: .csv myFileName = Left(.FullName, Len(.FullName) - 4) 'add the new extension: .xls myFileName = myFileName & ".xls" .SaveAs Filename:=myFileName, FileFormat:=xlWorkbookNormal .Close savechanges:=False 'maybe??? End With End Sub Mark wrote: The file is originally a .csv file that i am formatting and then saving as an .xls file using the same file name, in the same folder and directory. "Dave Peterson" wrote: Are you saving the workbook with the code? Do you want to overwrite the existing workbook? If yes to both, you can use: thisworkbook.save If you want to save a different workbook with the same name as the workbook that's running the code, then nope--you can't use Save|As. You can only have one file open with any particular name. There may be other work arounds. You could save the file with a temporary name. Close that file. And then use the Name statement to rename it to what you want. There are other things to consider, too. Is the workbook opened readonly? Are you trying to use the same drive/path/filename or what???? Mark wrote: I created a simple formatting macro and included the "save As" in the macro, of course it wants to save the workbook as the name indicated in the macro. Can I have the macro save the workbook as the current workbook name? -- Dave Peterson -- Dave Peterson |
All times are GMT +1. The time now is 08:01 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com