![]() |
Save workbook problem
ThisWorkbook.SaveCopyAs Filename:="C:\Folder\XXXXX-" & inputText &
".xls" however if the file already exists I get an error "1004". I presume I require something like If 'ThisWorkbook exists' Then 'overwrite the existing file' Else ThisWorkbook.SaveCopyAs Filename:="C:\Folder\XXXXX-" & inputText & ".xls" End If Can anyone help with the required syntax for 'ThisWorkbook exists' and 'overwrite the existing file' - or if there is a better option. Many thanks in advance. Sandy |
Save workbook problem
Oops, I missed the first line of my query which should be :-
I have a macro which includes the line :- Sandy "Sandy" wrote in message ... ThisWorkbook.SaveCopyAs Filename:="C:\Folder\XXXXX-" & inputText & ".xls" however if the file already exists I get an error "1004". I presume I require something like If 'ThisWorkbook exists' Then 'overwrite the existing file' Else ThisWorkbook.SaveCopyAs Filename:="C:\Folder\XXXXX-" & inputText & ".xls" End If Can anyone help with the required syntax for 'ThisWorkbook exists' and 'overwrite the existing file' - or if there is a better option. Many thanks in advance. Sandy |
Save workbook problem
I don't think that the existing workbook is causing the trouble.
..savecopyas actually saves a copy of the workbook without any warning prompts. You could get that 1004 error if the workbook is in use (already open???). The error description was: "Cannot access --filenamehere.xls--'. If that's not the problem, you may want to share the description you see. And share what's in InputText, too. And make sure that C:\folder already exists. Sandy wrote: ThisWorkbook.SaveCopyAs Filename:="C:\Folder\XXXXX-" & inputText & ".xls" however if the file already exists I get an error "1004". I presume I require something like If 'ThisWorkbook exists' Then 'overwrite the existing file' Else ThisWorkbook.SaveCopyAs Filename:="C:\Folder\XXXXX-" & inputText & ".xls" End If Can anyone help with the required syntax for 'ThisWorkbook exists' and 'overwrite the existing file' - or if there is a better option. Many thanks in advance. Sandy -- Dave Peterson |
Save workbook problem
You are dead right Dave, I was basically testing the code and was trying to
save under the same name when , of course the fie was already open. When I save under the same name of a closed file it does indeed overwrite it. Thanks for your assistance Sandy "Dave Peterson" wrote in message ... I don't think that the existing workbook is causing the trouble. .savecopyas actually saves a copy of the workbook without any warning prompts. You could get that 1004 error if the workbook is in use (already open???). The error description was: "Cannot access --filenamehere.xls--'. If that's not the problem, you may want to share the description you see. And share what's in InputText, too. And make sure that C:\folder already exists. Sandy wrote: ThisWorkbook.SaveCopyAs Filename:="C:\Folder\XXXXX-" & inputText & ".xls" however if the file already exists I get an error "1004". I presume I require something like If 'ThisWorkbook exists' Then 'overwrite the existing file' Else ThisWorkbook.SaveCopyAs Filename:="C:\Folder\XXXXX-" & inputText & ".xls" End If Can anyone help with the required syntax for 'ThisWorkbook exists' and 'overwrite the existing file' - or if there is a better option. Many thanks in advance. Sandy -- Dave Peterson |
All times are GMT +1. The time now is 07:29 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com