PC Review


Reply
Thread Tools Rate Thread

Check for Folder

 
 
Arnie
Guest
Posts: n/a
 
      22nd Oct 2008
i have this code supplied by Joel which i have changed but i always get a
FindFolder="" when the folder is there

RootFolder = ThisWorkbook.Path
DestinationFolder = "\The_Folder_im_LookingFor"

Dim FindFolder As String
FindFolder = ""
On Error Resume Next

FindFolder = RootFolder & DestinationFolder

On Error GoTo 0

If FindFolder = "" Then
'not there

Worksheets("Macros").Run_All.Visible = False
Worksheets("Macros").Run_All.Enabled = False
Else
'is there

Worksheets("Macros").Run_All.Visible = True
Worksheets("Macros").Run_All.Enabled = True


 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      22nd Oct 2008
This isn't the code I provided. Add a message box to help diagnose the problem

from
FindFolder = RootFolder & DestinationFolder

to
msgbox(RootFolder & DestinationFolder)

It is impossible for the code you posted for FindFolder to equal an empty
string ""

FindFolder = RootFolder & DestinationFolder

"Arnie" wrote:

> i have this code supplied by Joel which i have changed but i always get a
> FindFolder="" when the folder is there
>
> RootFolder = ThisWorkbook.Path
> DestinationFolder = "\The_Folder_im_LookingFor"
>
> Dim FindFolder As String
> FindFolder = ""
> On Error Resume Next
>
> FindFolder = RootFolder & DestinationFolder
>
> On Error GoTo 0
>
> If FindFolder = "" Then
> 'not there
>
> Worksheets("Macros").Run_All.Visible = False
> Worksheets("Macros").Run_All.Enabled = False
> Else
> 'is there
>
> Worksheets("Macros").Run_All.Visible = True
> Worksheets("Macros").Run_All.Enabled = True
>
>

 
Reply With Quote
 
Arnie
Guest
Posts: n/a
 
      22nd Oct 2008
Joel hi sorry this was the code you supplied

Set ScriptObj = CreateObject("Scripting.FileSystemObject")


'Check if Folder already exists
Found = False
Set F = ScriptObj.GetFolder(RootFolder)
For Each Folder In F.Subfolders
If Folder.Name = DestinationFolder Then
Found = True
Exit For
End If
Next Folder

'if folder does not exist then create
If Found = False Then
'Generate Folder
ScriptObj.CreateFolder (RootFolder & DestinationFolder)
End If

DestFolder = RootFolder & "\Generated_Scripts\"

but i always get found to be false i don't need to create the folder just
make sure its there.

appologies for not putting in correct code

"Joel" wrote:

> This isn't the code I provided. Add a message box to help diagnose the problem
>
> from
> FindFolder = RootFolder & DestinationFolder
>
> to
> msgbox(RootFolder & DestinationFolder)
>
> It is impossible for the code you posted for FindFolder to equal an empty
> string ""
>
> FindFolder = RootFolder & DestinationFolder
>
> "Arnie" wrote:
>
> > i have this code supplied by Joel which i have changed but i always get a
> > FindFolder="" when the folder is there
> >
> > RootFolder = ThisWorkbook.Path
> > DestinationFolder = "\The_Folder_im_LookingFor"
> >
> > Dim FindFolder As String
> > FindFolder = ""
> > On Error Resume Next
> >
> > FindFolder = RootFolder & DestinationFolder
> >
> > On Error GoTo 0
> >
> > If FindFolder = "" Then
> > 'not there
> >
> > Worksheets("Macros").Run_All.Visible = False
> > Worksheets("Macros").Run_All.Enabled = False
> > Else
> > 'is there
> >
> > Worksheets("Macros").Run_All.Visible = True
> > Worksheets("Macros").Run_All.Enabled = True
> >
> >

 
Reply With Quote
 
Arnie
Guest
Posts: n/a
 
      22nd Oct 2008
Joel sorted it i took out the \ in "\The_Folder_im_LookingFor"

and works fine

thank you for your help

"Joel" wrote:

> This isn't the code I provided. Add a message box to help diagnose the problem
>
> from
> FindFolder = RootFolder & DestinationFolder
>
> to
> msgbox(RootFolder & DestinationFolder)
>
> It is impossible for the code you posted for FindFolder to equal an empty
> string ""
>
> FindFolder = RootFolder & DestinationFolder
>
> "Arnie" wrote:
>
> > i have this code supplied by Joel which i have changed but i always get a
> > FindFolder="" when the folder is there
> >
> > RootFolder = ThisWorkbook.Path
> > DestinationFolder = "\The_Folder_im_LookingFor"
> >
> > Dim FindFolder As String
> > FindFolder = ""
> > On Error Resume Next
> >
> > FindFolder = RootFolder & DestinationFolder
> >
> > On Error GoTo 0
> >
> > If FindFolder = "" Then
> > 'not there
> >
> > Worksheets("Macros").Run_All.Visible = False
> > Worksheets("Macros").Run_All.Enabled = False
> > Else
> > 'is there
> >
> > Worksheets("Macros").Run_All.Visible = True
> > Worksheets("Macros").Run_All.Enabled = True
> >
> >

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      22nd Oct 2008
This code isn't creating a folder unless it isn't found.

Set F = ScriptObj.GetFolder(RootFolder)

This statment is getting the parent folder

Then the for loop below is checking if the sub folder exists which is
DestinationFolder. Again the code you posted doesn't have DestinationFolder
assigned.

For Each Folder In F.Subfolders
If Folder.Name = DestinationFolder Then
Found = True
Exit For
End If
Next Folder



"Arnie" wrote:

> Joel hi sorry this was the code you supplied
>
> Set ScriptObj = CreateObject("Scripting.FileSystemObject")
>
>
> 'Check if Folder already exists
> Found = False
> Set F = ScriptObj.GetFolder(RootFolder)
> For Each Folder In F.Subfolders
> If Folder.Name = DestinationFolder Then
> Found = True
> Exit For
> End If
> Next Folder
>
> 'if folder does not exist then create
> If Found = False Then
> 'Generate Folder
> ScriptObj.CreateFolder (RootFolder & DestinationFolder)
> End If
>
> DestFolder = RootFolder & "\Generated_Scripts\"
>
> but i always get found to be false i don't need to create the folder just
> make sure its there.
>
> appologies for not putting in correct code
>
> "Joel" wrote:
>
> > This isn't the code I provided. Add a message box to help diagnose the problem
> >
> > from
> > FindFolder = RootFolder & DestinationFolder
> >
> > to
> > msgbox(RootFolder & DestinationFolder)
> >
> > It is impossible for the code you posted for FindFolder to equal an empty
> > string ""
> >
> > FindFolder = RootFolder & DestinationFolder
> >
> > "Arnie" wrote:
> >
> > > i have this code supplied by Joel which i have changed but i always get a
> > > FindFolder="" when the folder is there
> > >
> > > RootFolder = ThisWorkbook.Path
> > > DestinationFolder = "\The_Folder_im_LookingFor"
> > >
> > > Dim FindFolder As String
> > > FindFolder = ""
> > > On Error Resume Next
> > >
> > > FindFolder = RootFolder & DestinationFolder
> > >
> > > On Error GoTo 0
> > >
> > > If FindFolder = "" Then
> > > 'not there
> > >
> > > Worksheets("Macros").Run_All.Visible = False
> > > Worksheets("Macros").Run_All.Enabled = False
> > > Else
> > > 'is there
> > >
> > > Worksheets("Macros").Run_All.Visible = True
> > > Worksheets("Macros").Run_All.Enabled = True
> > >
> > >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check for the existence of the Temporary folder namedTemporary Folder a , 2 and so on before deleting as the name is not fixed Yuvraj Microsoft Excel Programming 1 3rd May 2009 09:41 PM
How to check for the existence of the Temporary folder namedTemporary Folder 1,2 and so on As Yuvraj Microsoft Excel Programming 0 3rd May 2009 04:55 PM
When I try to open/save .rtf attachment I get the messages ?Can't create file. Right-click the folder you want to create item in and then click on the shortcut menu to check your permissions for the folder.? Nie Geweune via AdminLife Microsoft Outlook Installation 2 28th Jun 2006 05:07 PM
Check if folder exists, if yes just copy sheet in to folder? Simon Lloyd Microsoft Excel Programming 3 19th Jun 2006 03:44 PM
DLL check in Bin folder John Microsoft ASP .NET 1 8th Feb 2005 05:30 PM


Features
 

Advertising
 

Newsgroups
 


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