Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Error - file already exists.


I have the letters A - O in rows 1 - 15 of column A on my Excel
spreadsheet. However, instead of the following routine making
subfolders under C:\RESERVES I get the error "file already exists".
Can someone help?

Thanks,

Jim


Sub createfolders()
'
' CreateFolders Macro
' Macro recorded 3/22/2006 by JBW
'
Dim cou As Integer, FolderStr As String, FileSys
For cou = 1 To ActiveSheet.UsedRange.Rows.Count
FolderStr = Format(Trim(Str(cou)), "00#") + "_" +
ActiveSheet.Cells(cou, 1)
Set FileSys = CreateObject("Scripting.FileSystemObject")
FileSys.createfolder "C:\RESERVES"
Next
End Sub


--
Jim15
------------------------------------------------------------------------
Jim15's Profile: http://www.excelforum.com/member.php...o&userid=26300
View this thread: http://www.excelforum.com/showthread...hreadid=527191

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Error - file already exists.

Jim,
'-------------------
Sub createfolders()
Dim cou As Long
Dim FolderStr As String
Dim FileSys As Object

For cou = 1 To ActiveSheet.UsedRange.Rows.Count
FolderStr = Format$(Trim$(cou), "00#") & "_" & ActiveSheet.Cells(cou, 1).Value
Set FileSys = CreateObject("Scripting.FileSystemObject")
FileSys.createfolder "C:\RESERVES\" & FolderStr
Next
Set FileSys = Nothing
End Sub
'----------
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"Jim15"wrote in message...
I have the letters A - O in rows 1 - 15 of column A on my Excel
spreadsheet. However, instead of the following routine making
subfolders under C:\RESERVES I get the error "file already exists".
Can someone help?
Thanks,
Jim


Sub createfolders()
'
' CreateFolders Macro
' Macro recorded 3/22/2006 by JBW
'
Dim cou As Integer, FolderStr As String, FileSys
For cou = 1 To ActiveSheet.UsedRange.Rows.Count
FolderStr = Format(Trim(Str(cou)), "00#") + "_" +
ActiveSheet.Cells(cou, 1)
Set FileSys = CreateObject("Scripting.FileSystemObject")
FileSys.createfolder "C:\RESERVES"
Next
End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Error - file already exists.

Jim,
The other Jim has fixed the code, but do you really need to create an
instance of the FSO just to make a folder.
You do have the native MkDir.

NickHK

"Jim15" wrote in
message ...

I have the letters A - O in rows 1 - 15 of column A on my Excel
spreadsheet. However, instead of the following routine making
subfolders under C:\RESERVES I get the error "file already exists".
Can someone help?

Thanks,

Jim


Sub createfolders()
'
' CreateFolders Macro
' Macro recorded 3/22/2006 by JBW
'
Dim cou As Integer, FolderStr As String, FileSys
For cou = 1 To ActiveSheet.UsedRange.Rows.Count
FolderStr = Format(Trim(Str(cou)), "00#") + "_" +
ActiveSheet.Cells(cou, 1)
Set FileSys = CreateObject("Scripting.FileSystemObject")
FileSys.createfolder "C:\RESERVES"
Next
End Sub


--
Jim15
------------------------------------------------------------------------
Jim15's Profile:

http://www.excelforum.com/member.php...o&userid=26300
View this thread: http://www.excelforum.com/showthread...hreadid=527191



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Error - file already exists.

Hi NickHK,
I almost fixed the code. <g
The Set statement should be placed before the loop, not in it.
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"NickHK" wrote in message
...
Jim,
The other Jim has fixed the code, but do you really need to create an
instance of the FSO just to make a folder.
You do have the native MkDir.

NickHK


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Error - file already exists.

Jim,
Well, I didn't look too closely at your code..
Just wondering why everybody wants to use FSO nowadays for functions that
are easily accomplished without it.
Given that it may be disabled on some systems, is notoriously slow and
suffers from numerous versions, why bother ?

NickHK

"Jim Cone" wrote in message
...
Hi NickHK,
I almost fixed the code. <g
The Set statement should be placed before the loop, not in it.
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"NickHK" wrote in message
...
Jim,
The other Jim has fixed the code, but do you really need to create an
instance of the FSO just to make a folder.
You do have the native MkDir.

NickHK






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Error - file already exists.

NickHK,

You are course correct that it doesn't make sense to use the FileSystemObject
(FSO) when you don't have to. However, FSO does have some virtues?

It remains unchanged since 2001 and essentially will work in any system
with IE 4/ Windows NT4.0 and up.
I don't believe any other MS code system has been that stable.
The code is logical and easy to learn.
It does what it says it will do; you can rely on it.
It is far superior to using FileSearch.

Randy Birch has done some tests using FSO and (no surprise) the winner is...
the FindFirstFile APIs.
http://vbnet.mvps.org/index.html?cod...barmessage.htm

Regards,
Jim Cone
San Francisco, USA


"NickHK" wrote in message ...
Jim,
Well, I didn't look too closely at your code..
Just wondering why everybody wants to use FSO nowadays for functions that
are easily accomplished without it.
Given that it may be disabled on some systems, is notoriously slow and
suffers from numerous versions, why bother ?
NickHK

"Jim Cone" wrote in message
...
Hi NickHK,
I almost fixed the code. <g
The Set statement should be placed before the loop, not in it.
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"NickHK" wrote in message
...
Jim,
The other Jim has fixed the code, but do you really need to create an
instance of the FSO just to make a folder.
You do have the native MkDir.
NickHK

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
Macro to move files gets an error if it already exists... [email protected] Excel Worksheet Functions 6 March 7th 07 09:46 PM
Excel PageSetup Error even when a printer Exists jo Excel Programming 1 January 11th 06 02:21 AM
Error if 'name' already exists Kevin O'Neill[_2_] Excel Programming 9 November 16th 05 06:28 PM
File Name Exists Error Trap Mike Excel Programming 2 February 21st 04 01:30 AM
the file already exists - do you want to replace the existing file? Paul James[_3_] Excel Programming 4 December 12th 03 02:50 AM


All times are GMT +1. The time now is 08:47 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"