Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Catching duplicate filenames when renaming a file

Hi,

In my code I have to rename some files, using the command:

Name oldfilename as newfilename

Sometimes the newfilename already exists so I am looking for a way to
detect that condition, I tried:

If iserror(Name oldfilename as newfilename) then
CODE HERE
else
name oldfilename as newfilename
end if

However, Excel "Expects list seperator or )" around the oldfilename in
the iserror statement. Help!

Also, for this code I am in the middle of an application filesearch so
I can't search for the file using application.filesearch.

Thank you!!!

Phil

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default Catching duplicate filenames when renaming a file

Phil,

How about

If Dir(newfilename)<"" then
'the file exists
else
'save the file
end if

Robin Hammond
www.enhanceddatasystems.com

"General" wrote in message
ups.com...
Hi,

In my code I have to rename some files, using the command:

Name oldfilename as newfilename

Sometimes the newfilename already exists so I am looking for a way to
detect that condition, I tried:

If iserror(Name oldfilename as newfilename) then
CODE HERE
else
name oldfilename as newfilename
end if

However, Excel "Expects list seperator or )" around the oldfilename in
the iserror statement. Help!

Also, for this code I am in the middle of an application filesearch so
I can't search for the file using application.filesearch.

Thank you!!!

Phil



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Catching duplicate filenames when renaming a file

Another way

On Error Resume Next
Name oldfilename As newfilename
If Err.Number = 58 Then 'already exists
MsgBox "file " & newfilename & " already exists"
End If
On Error GoTo 0


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Robin Hammond" wrote in message
...
Phil,

How about

If Dir(newfilename)<"" then
'the file exists
else
'save the file
end if

Robin Hammond
www.enhanceddatasystems.com

"General" wrote in message
ups.com...
Hi,

In my code I have to rename some files, using the command:

Name oldfilename as newfilename

Sometimes the newfilename already exists so I am looking for a way to
detect that condition, I tried:

If iserror(Name oldfilename as newfilename) then
CODE HERE
else
name oldfilename as newfilename
end if

However, Excel "Expects list seperator or )" around the oldfilename in
the iserror statement. Help!

Also, for this code I am in the middle of an application filesearch so
I can't search for the file using application.filesearch.

Thank you!!!

Phil





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Catching duplicate filenames when renaming a file

Thanks, that solves it for me!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB file renaming. El Bee Excel Worksheet Functions 2 January 23rd 08 01:49 AM
Renaming A File Rose Excel Discussion (Misc queries) 2 December 14th 06 05:33 PM
CATCHING DUPLICATE INFORMATION IN DIFFERENT CELLS SAME PROGRAM Lisa Setting up and Configuration of Excel 1 July 20th 06 05:21 PM
Catching an Open Excel File with VBScript onedaywhen Excel Programming 2 April 6th 04 09:54 AM
Renaming a file Paul C[_2_] Excel Programming 1 January 23rd 04 04:13 PM


All times are GMT +1. The time now is 01:03 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"