Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro to move files gets an error if it already exists... | Excel Worksheet Functions | |||
Excel PageSetup Error even when a printer Exists | Excel Programming | |||
Error if 'name' already exists | Excel Programming | |||
File Name Exists Error Trap | Excel Programming | |||
the file already exists - do you want to replace the existing file? | Excel Programming |