Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi'
I have a macro copying files to specifik folders. I only have one problem, if the folder is not created then the script stops. How do I let the script ignore this file and just move on to the next? I suppose i need to check if the destination folder exist, but how? Thanks |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
an old post by Bob Philips says:
'################################ 1. Use DIR to test, and FileSystemObject to create it Dim myDir, myFile myFile = "C:\Billing\Invoices\SepInv\" myDir = Dir(myFile) If myDir < "" Then MsgBox "Directory already exists" Else myDir = CreateObject("Scripting.FileSystemObject").createF older(myFile) End If 2. Use FileSystemObject for both Dim myDir, myFile myFile = "C:\Billing\Invoices\SepInv\" myDir = CreateObject("Scripting.FileSystemObject").FolderE xists(myFile) If myDir = True Then MsgBox "Directory already exists" Else myDir = CreateObject("Scripting.FileSystemObject").createF older(myFile) End If '####################################### I'm sure the above must help Rgds J On 29 Nov, 12:41, "HH" wrote: Hi' I have a macro copying files to specifik folders. I only have one problem, if the folder is not created then the script stops. How do I let the script ignore this file and just move on to the next? I suppose i need to check if the destination folder exist, but how? Thanks |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Use code like the following:
Dim FolderExists As Boolean Dim FolderName As String FolderName = "C:\Test1234" FolderExists = (Dir(FolderName, vbDirectory + vbHidden) < vbNullString) If FolderExists = False Then ''''''''''''''''''''''''''''''''''' ' If the folder doesn't exist, use ' MkDir to create the folder. ''''''''''''''''''''''''''''''''''' On Error Resume Next Err.Clear MkDir FolderName If Err.Number < 0 Then MsgBox "An error occurred with MkDir:" & vbCrLf & _ "Err: " & CStr(Err.Number) & vbCrLf & _ "Desc: " & Err.Description End If On Error GoTo 0 End If -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com (email address is on the web site) "MichDenis" wrote in message ... | myFile = "C:\Billing\Invoices\SepInv\" | myDir = Dir(myFile) | If myDir < "" Then | MsgBox "Directory already exists" This does not work if the folder is empty... It's better if you use this : myDir = Dir(myFile, vbDirectory) "WhytheQ" a écrit dans le message de news: ... an old post by Bob Philips says: '################################ 1. Use DIR to test, and FileSystemObject to create it Dim myDir, myFile myFile = "C:\Billing\Invoices\SepInv\" myDir = Dir(myFile) If myDir < "" Then MsgBox "Directory already exists" Else myDir = CreateObject("Scripting.FileSystemObject").createF older(myFile) End If 2. Use FileSystemObject for both Dim myDir, myFile myFile = "C:\Billing\Invoices\SepInv\" myDir = CreateObject("Scripting.FileSystemObject").FolderE xists(myFile) If myDir = True Then MsgBox "Directory already exists" Else myDir = CreateObject("Scripting.FileSystemObject").createF older(myFile) End If '####################################### I'm sure the above must help Rgds J On 29 Nov, 12:41, "HH" wrote: Hi' I have a macro copying files to specifik folders. I only have one problem, if the folder is not created then the script stops. How do I let the script ignore this file and just move on to the next? I suppose i need to check if the destination folder exist, but how? Thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Save file in a new folder, but create folder only if folder doesn't already exist? | Excel Programming | |||
Create Folder If It Doesn't Exist | Excel Programming | |||
Does folder exist problem | Excel Programming | |||
How to: check if folder exist, if not, create | Excel Programming | |||
How to check if a folder/directory exist using VBA | Excel Programming |