ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Check if specifik folder exist. (https://www.excelbanter.com/excel-programming/378411-check-if-specifik-folder-exist.html)

HH[_2_]

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


WhytheQ

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



michdenis

Check if specifik folder exist.
 
| 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





Chip Pearson

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







HH[_2_]

Check if specifik folder exist.
 

Thanks - its working now.

HH



All times are GMT +1. The time now is 10:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com