Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Check if specifik folder exist.

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Check if specifik folder exist.

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Check if specifik folder exist.

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
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
Save file in a new folder, but create folder only if folder doesn't already exist? nbaj2k[_40_] Excel Programming 6 August 11th 06 08:41 PM
Create Folder If It Doesn't Exist Neutron1871 Excel Programming 4 May 6th 05 01:42 AM
Does folder exist problem Jeff Excel Programming 3 January 31st 05 03:22 PM
How to: check if folder exist, if not, create escorido[_2_] Excel Programming 2 July 9th 04 01:28 PM
How to check if a folder/directory exist using VBA wellie Excel Programming 1 March 1st 04 02:24 AM


All times are GMT +1. The time now is 07:26 AM.

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

About Us

"It's about Microsoft Excel"