Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Save workbook problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sandy - 20 Mar 2008 23:54 GMT
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
Sandy - 21 Mar 2008 00:19 GMT
Oops, I missed the first line of my query which should be :-

I have a macro which includes the line :-

Sandy

>    ThisWorkbook.SaveCopyAs Filename:="C:\Folder\XXXXX-" & inputText &
> ".xls"
[quoted text clipped - 14 lines]
> Many thanks in advance.
> Sandy
Dave Peterson - 21 Mar 2008 00:54 GMT
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.

>     ThisWorkbook.SaveCopyAs Filename:="C:\Folder\XXXXX-" & inputText &
> ".xls"
[quoted text clipped - 14 lines]
> Many thanks in advance.
> Sandy

Signature

Dave Peterson

Sandy - 21 Mar 2008 11:00 GMT
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

> I don't think that the existing workbook is causing the trouble.
>
[quoted text clipped - 29 lines]
>> Many thanks in advance.
>> Sandy
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.