+ Reply to Thread
Results 1 to 13 of 13

Hello and Help needed with folder creation

Hybrid View

pdj Hello and Help needed with... 01-26-2014, 10:12 AM
LJMetzger Re: Hello and Help needed... 01-26-2014, 10:49 AM
pdj Re: Hello and Help needed... 01-26-2014, 10:58 AM
pdj Re: Hello and Help needed... 01-26-2014, 11:18 AM
LJMetzger Re: Hello and Help needed... 01-26-2014, 12:42 PM
pdj Thanks Lewis - much... 01-26-2014, 12:50 PM
pdj Re: Hello and Help needed... 01-27-2014, 10:34 AM
LJMetzger Re: Hello and Help needed... 01-27-2014, 12:25 PM
pdj Re: Hello and Help needed... 01-27-2014, 04:16 PM
LJMetzger Re: Hello and Help needed... 01-27-2014, 05:01 PM
pdj Re: Hello and Help needed... 01-27-2014, 05:56 PM
LJMetzger Re: Hello and Help needed... 01-27-2014, 06:33 PM
pdj Thanks Lewis! We have a... 01-28-2014, 03:09 PM
  1. #1
    Registered User
    Join Date
    01-26-2014
    Location
    Chorley, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Question Hello and Help needed with folder creation

    Hi all

    I'm new to this forum and indeed to VBA and could do with a little help

    I've a spreadsheet which contains a lists of files which I want to copy into a new folder within "C:\Users\Paul\Briefing Pack Selector\Output\" and then a subfolder which will reflect a variable name depending upon what is entered into cell "C3" on the worksheet "Briefing Pack Selector". I have the following macro code which successfully copies the files to "C:\Users\Paul\Briefing Pack Selector\Output\" but I just can't figure out how to write the extra step to make the new folder:


    Sub cmd_CopyPk1()
    
    Sheets("Briefing Pack 1").Select
    Dim a As Integer, x As Integer
    Dim b As String
    x = Cells(Rows.Count, 1).End(xlUp).Row
    For a = 1 To x
    b = Cells(a, 1)
    FileCopy "C:\Users\Paul\Briefing Pack Selector\Pack Contents\" & b, "C:\Users\Paul\Briefing Pack Selector\Output\" & b
    Next a
    MsgBox "Files have been copied to output folder"
    Sheets("Briefing Pack Selector").Select
    End Sub

    Any help you can give will be most appreciated.

    Many thanks in advance

    Paul
    Last edited by pdj; 01-26-2014 at 10:30 AM.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Hello and Help needed with folder creation

    Hi Paul,

    See the attached working example. I included a few extra file functions in case you might need them in the future.

    Lewis

    Sub CreateFolder()
    
      Const sARCHIVE_FOLDER_NAME = "ArchiveXXX"
    
      Dim sPath As String
      
    
      sPath = ActiveWorkbook.Path & "\"
    
      'Create the 'Archive' Folder (subdirectory)
      'The function called creates the directory if it doesn't exist
      If LjmDirectoryCreate(sPath, sARCHIVE_FOLDER_NAME) <> 0 Then
        MsgBox "Software Integrity Error.  Program terminating." & vbCrLf & _
        "Folder (sub-directory) '" & sARCHIVE_FOLDER_NAME & "' could NOT be created."
        Exit Sub
      End If
    
    End Sub
    
    Public Function LjmDirectoryCreate(sPath As String, sDirectory As String) As Integer
      'This checks to see if a directory exists.
      'If the directory DOES NOT EXIST, the directory is CREATED.
      'Return values are as follows:
      '  0 = success
      '  1 = source file not found
    
    
      Dim sPathAndFolder As String
    
    
      LjmDirectoryCreate = 0
    
      sDirectory = sDirectory
    
      sPathAndFolder = sPath & sDirectory
    
      'If directory does NOT EXIST, CREATE the directory
      If LJMFolderExists(sPathAndFolder) = False Then
      
        '''''''''''''''''''''''''''''''''''''''''
        'Create Directory
        '''''''''''''''''''''''''''''''''''''''''
        MkDir sPathAndFolder
        
        
        'Make sure the directory exists or was created correctly
        If LJMFolderExists(sPathAndFolder) = False Then
          LjmDirectoryCreate = 0
        End If
    
      End If
    
    End Function
    
     
    Public Function LJMFolderExists(sPathAndFullFileName As String) As Boolean
      'This returns TRUE if a folder exists and FALSE if a folder does NOT exist
      'This will return FALSE if the 'sPathAndFullFileName' is a file
      
      Dim iFileAttributes As Integer
    
      On Error Resume Next
      iFileAttributes = GetAttr(sPathAndFullFileName)
      iFileAttributes = iFileAttributes And vbDirectory
      On Error GoTo 0
         
      LJMFolderExists = False
      If iFileAttributes = vbDirectory Then
        LJMFolderExists = True
      End If
      
    End Function
    
    Public Function LJMFileExists(sPathAndFullFileName As String) As Boolean
      'This returns TRUE if a file exists and FALSE if a file does NOT exist
      
      Dim iError As Integer
      Dim iFileAttributes As Integer
    
      On Error Resume Next
      iFileAttributes = GetAttr(sPathAndFullFileName)
         
      'Check the internal error  return
      iError = Err.Number
      Select Case iError
        Case Is = 0
            iFileAttributes = iFileAttributes And vbDirectory
            If iFileAttributes = 0 Then
              LJMFileExists = True
            Else
              LJMFileExists = False
            End If
        Case Else
            LJMFileExists = False
      End Select
    
      On Error GoTo 0
    
    End Function
    Public Function LJMFileIsDirectory(sPathAndFullFileName As String) As Boolean
      'This returns TRUE if a file is a Directory and FALSE if a file does NOT exist or is a file
      
      Dim iError As Integer
      Dim iFileAttributes As Integer
    
      On Error Resume Next
      iFileAttributes = GetAttr(sPathAndFullFileName)
         
      'Check the internal error  return
      iError = Err.Number
      If iError = 0 Then
        iFileAttributes = iFileAttributes And vbDirectory
        If iFileAttributes <> 0 Then
          LJMFileIsDirectory = True
        End If
      End If
      
      On Error GoTo 0
    
    End Function
    
    Public Function LJMFileOrFolderExists(sPathAndFullFileName As String) As Boolean
      'This returns TRUE if a file or folder exists and FALSE if a file or folder does NOT exist
      
      Dim iError As Integer
      Dim iFileAttributes As Integer
    
      On Error Resume Next
      iFileAttributes = GetAttr(sPathAndFullFileName)
         
      'Check the internal error  return
      iError = Err.Number
      Select Case iError
        Case Is = 0
            LJMFileOrFolderExists = True
        Case Else
            LJMFileOrFolderExists = False
      End Select
    
      On Error GoTo 0
    
    End Function

  3. #3
    Registered User
    Join Date
    01-26-2014
    Location
    Chorley, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Hello and Help needed with folder creation

    Thank you so much Lewis! - I'll have a play

    All the best

    Paul

  4. #4
    Registered User
    Join Date
    01-26-2014
    Location
    Chorley, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Hello and Help needed with folder creation

    Sorry Lewis - I'm struggling still.

    Your code is too advanced for me - I'm not sure how it should link with my original code (if at all). Are you able to give any guidance?

    Many thanks

    Paul

  5. #5
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Hello and Help needed with folder creation

    Hi Paul,

    Try the following code. I simplified it a little, and incorporated your code as best as I could. If you single step thru it using 'SHIFT f8' it will be easier to understand. I tested it using Excel 2003 and the create subfolder part works.

    Please delete anything from your workbook that you copied from me previously. There is nothing wrong with my code, but if you have duplicate copies of routines, Excel 2003 can LOCK UP.

    If you have any more questions please ask.

    Lewis

    Option Explicit
    
    
    Sub cmd_CopyPk1_By_Lewis()
    
      Dim a As Integer
      Dim iNumberOfFiles As Integer
      Dim b As String
      
      Dim sDestinationFolder As String
      Dim sFileName As String
      Dim sSourceFolder As String
      Dim sSubFolderName As String
      Dim sPathAndSubFolderName As String
      
      sSourceFolder = "C:\Users\Paul\Briefing Pack Selector\Pack Contents\"
      sDestinationFolder = "C:\Users\Paul\Briefing Pack Selector\Output\"
      
      'The following were debugging statement(s) used by Lewis (can be ignored or deleted)
    #Const Lewis = False
    #If Lewis Then
      sSourceFolder = ThisWorkbook.Path & "\"
      sDestinationFolder = ThisWorkbook.Path & "\"
    #End If
    
      Sheets("Briefing Pack 1").Select
      
      'Copy Source files to the 'Output Folder'
      iNumberOfFiles = Cells(Rows.Count, 1).End(xlUp).Row
      
      'The following were debugging statement(s) used by Lewis (can be ignored or deleted)
    #If Lewis Then
      iNumberOfFiles = 0 
    #End If
    
      For a = 1 To iNumberOfFiles
        sFileName = Cells(a, 1)
        FileCopy sSourceFolder & sFileName, sDestinationFolder & sFileName
      Next a
      
      '**********************************************************
      'Option 1 - Create a New Subfolder if it is a complete name (path and file) in Cell 'C3'
      '**********************************************************
      
      'Get the Subfolder name  (including path)
      sPathAndSubFolderName = Sheets("Briefing Pack Selector").Range("C3").Text
      
      'Strip out leading and trailing spaces from the name
      sPathAndSubFolderName = Trim(sPathAndSubFolderName)
      
      'Make sure the name is NOT BLANK
      If Len(sPathAndSubFolderName) = 0 Then
        MsgBox "Terminating.  The contents of cell 'C3' is BLANK"
        'Exit (i.e. 'Exit Sub' or do some other kind of error processing)
      End If
      
      'Create the new SubFolder (if it doesn't already exist)
      If LJMFolderExists(sPathAndSubFolderName) = False Then
        MkDir sPathAndSubFolderName
      
        If LJMFolderExists(sPathAndSubFolderName) = False Then
          MsgBox "Error in creating Subfolder: " & vbCrLf & _
                 "Name: " & sPathAndSubFolderName
        End If
      End If
      
      
      '**********************************************************
      'Option 2 - Create a New Subfolder if it is not a completed path (.e.g. 'Archive')
      'that is a subfolder of 'C:\Users\Paul\Briefing Pack Selector\Output\'
      '**********************************************************
      
      'Create the Subfolder name
      '
      'NOTE: I arbitrarily chose 'C4' for this file name - for example purposes only
      sSubFolderName = Sheets("Briefing Pack Selector").Range("C4").Text
      
      'Strip out leading and trailing spaces from the name
      sPathAndSubFolderName = Trim(sPathAndSubFolderName)
      
      'Make sure the name is NOT BLANK
      If Len(sSubFolderName) = 0 Then
        MsgBox "Terminating.  The contents of cell 'C3' is BLANK"
        'Exit (i.e. 'Exit Sub' or do some other kind of error processing)
      End If
      
      'Create the complete Sub Folder path and file name
      'NOTE: 'sDestinationFolder' MUST have a trailing '\' (as it does in your case)
      sPathAndSubFolderName = sDestinationFolder & sSubFolderName
      
      'Create the new SubFolder (if it doesn't already exist)
      If LJMFolderExists(sPathAndSubFolderName) = False Then
        MkDir sPathAndSubFolderName
      
        If LJMFolderExists(sPathAndSubFolderName) = False Then
          MsgBox "Error in creating Subfolder: " & vbCrLf & _
                 "Name: " & sPathAndSubFolderName
        End If
      End If
      
      
      MsgBox "Files have been copied to output folder"
      
      
      Sheets("Briefing Pack Selector").Select
    End Sub
    
     
    Public Function LJMFolderExists(sPathAndFullFileName As String) As Boolean
      'This returns TRUE if a folder exists and FALSE if a folder does NOT exist
      'This will return FALSE if the 'sPathAndFullFileName' is a file
      
      Dim iFileAttributes As Integer
    
      On Error Resume Next
      iFileAttributes = GetAttr(sPathAndFullFileName)
      iFileAttributes = iFileAttributes And vbDirectory
      On Error GoTo 0
         
      LJMFolderExists = False
      If iFileAttributes = vbDirectory Then
        LJMFolderExists = True
      End If
      
    End Function
    Last edited by LJMetzger; 01-26-2014 at 01:04 PM.

  6. #6
    Registered User
    Join Date
    01-26-2014
    Location
    Chorley, England
    MS-Off Ver
    Excel 2003
    Posts
    8
    Thanks Lewis - much appreciated!

    I will try the new code this evening.

    Best regards

    Paul

  7. #7
    Registered User
    Join Date
    01-26-2014
    Location
    Chorley, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Hello and Help needed with folder creation

    Hi Lewis

    Sorry to bother you again

    Your code is working great in that the desired folder is being created but the actual files are copying into the "C:\Users\Paul\Briefing Pack Selector\Output\" folder rather than the newly reated folder within the "...\Output\" folder.

    Do you have any ideas where I'm going wrong?

    Many thanks (again)

    Paul

  8. #8
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Hello and Help needed with folder creation

    You created a New Subfolder named 'sPathAndSubFolderName'.

    Your previous copy was:
    FileCopy sSourceFolder & sFileName, sDestinationFolder & sFileName
    You now have to create a NEW destination folder name to copy to the new SubFolder.
    For example (code excerpt not tested):
    'Create new Destination Folder from the New SubFolder name (needs trailing "\")
    sDestinationFolder = sPathAndSubFolderName & "\"
    
    'If you want to copy all the files to the new SubFolder, now
    'The Destination folder contains the name including the new SubFolder name.
     For a = 1 To iNumberOfFiles
        sFileName = Cells(a, 1)
        FileCopy sSourceFolder & sFileName, sDestinationFolder & sFileName
     Next a
    Lewis

  9. #9
    Registered User
    Join Date
    01-26-2014
    Location
    Chorley, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Hello and Help needed with folder creation

    Hi Lewis

    Your explanation makes sense but if I already have the code
    sDestinationFolder = "C:\Users\Paul\Briefing Pack Selector\Output\"
    How can I also have the code:

    sDestinationFolder = sPathAndSubFolderName & "\"
    This is the code I have in the project at present:

    Option Explicit
    
    
    Sub cmd_CopyPk1_By_Lewis()
    
      Dim a As Integer
      Dim iNumberOfFiles As Integer
      Dim b As String
      
      Dim sDestinationFolder As String
      Dim sFileName As String
      Dim sSourceFolder As String
      Dim sSubFolderName As String
      Dim sPathAndSubFolderName As String
      
      sSourceFolder = "C:\Users\Paul\Briefing Pack Selector\Pack Contents\"
      sDestinationFolder = "C:\Users\Paul\Briefing Pack Selector\Output\"
      
      Sheets("Briefing Pack 1").Select
      
      'Copy Source files to the 'Output Folder'
      iNumberOfFiles = Cells(Rows.Count, 1).End(xlUp).Row
      
      For a = 1 To iNumberOfFiles
        sFileName = Cells(a, 1)
        FileCopy sSourceFolder & sFileName, sDestinationFolder & sFileName
      Next a
    
     
      '**********************************************************
      'Option 1 - Create a New Subfolder if it is a complete name (path and file) in Cell 'C3'
      '**********************************************************
      
      'Get the Subfolder name  (including path)
      sPathAndSubFolderName = Sheets("Briefing Pack Selector").Range("C3").Text
      
      'Strip out leading and trailing spaces from the name
      sPathAndSubFolderName = Trim(sPathAndSubFolderName)
      
      'Make sure the name is NOT BLANK
      If Len(sPathAndSubFolderName) = 0 Then
        MsgBox "Terminating.  The contents of cell 'C3' is BLANK"
        'Exit (i.e. 'Exit Sub' or do some other kind of error processing)
      End If
      
      'Create the new SubFolder (if it doesn't already exist)
      If LJMFolderExists(sPathAndSubFolderName) = False Then
        MkDir sPathAndSubFolderName & "\"
      
        If LJMFolderExists(sPathAndSubFolderName) = False Then
          MsgBox "Error in creating Subfolder: " & vbCrLf & _
                 "Name: " & sPathAndSubFolderName
        End If
      End If
      
      
      '**********************************************************
      'Option 2 - Create a New Subfolder if it is not a completed path (.e.g. 'Archive')
      'that is a subfolder of 'C:\Users\Paul\Briefing Pack Selector\Output\'
      '**********************************************************
      
      'Create the Subfolder name
      '
      'NOTE: I arbitrarily chose 'C4' for this file name - for example purposes only
      sSubFolderName = Sheets("Briefing Pack Selector").Range("C3").Text
      
      'Strip out leading and trailing spaces from the name
      sPathAndSubFolderName = Trim(sPathAndSubFolderName)
      
      'Make sure the name is NOT BLANK
      If Len(sSubFolderName) = 0 Then
        MsgBox "Terminating.  The contents of cell 'C3' is BLANK"
        'Exit (i.e. 'Exit Sub' or do some other kind of error processing)
      End If
      
      'Create the complete Sub Folder path and file name
      'NOTE: 'sDestinationFolder' MUST have a trailing '\' (as it does in your case)
      sPathAndSubFolderName = sDestinationFolder & sSubFolderName
      
      'Create the new SubFolder (if it doesn't already exist)
      If LJMFolderExists(sPathAndSubFolderName) = False Then
        MkDir sPathAndSubFolderName & "\"
      
        If LJMFolderExists(sPathAndSubFolderName) = False Then
          MsgBox "Error in creating Subfolder: " & vbCrLf & _
                 "Name: " & sPathAndSubFolderName
        End If
      End If
      
      
      MsgBox "Files have been copied to output folder"
      
      
      Sheets("Briefing Pack Selector").Select
    End Sub
    
     
    Public Function LJMFolderExists(sPathAndFullFileName As String) As Boolean
      'This returns TRUE if a folder exists and FALSE if a folder does NOT exist
      'This will return FALSE if the 'sPathAndFullFileName' is a file
      
      Dim iFileAttributes As Integer
    
      On Error Resume Next
      iFileAttributes = GetAttr(sPathAndFullFileName)
      iFileAttributes = iFileAttributes And vbDirectory
      On Error GoTo 0
         
      LJMFolderExists = False
      If iFileAttributes = vbDirectory Then
        LJMFolderExists = True
      End If
      
    End Function
    Thanks again

    Paul

  10. #10
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Hello and Help needed with folder creation

    All we did was create the New Sub Folder, we didn't copy any information into it.

    To do that, we have to put the code in post #8 at the bottom of the code in post #9.

    Lewis

  11. #11
    Registered User
    Join Date
    01-26-2014
    Location
    Chorley, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Hello and Help needed with folder creation

    Hi Lewis

    You must be sick of me so this is my last question (and if I still can't get it then I'll burn my laptop, throw the ashes into the sea and hang my head in shame)

    If I add the post #8 code to the bottom of the post #9 code (I guessing you mean at the end of the sub before the Function - as it errors there), the files still copy onto the output folder and not the created one. It looks to me like the code is saying where to put the files before the folder is created - is this correct.

    Sorry!

    Paul

  12. #12
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Hello and Help needed with folder creation

    Yes. Try this (untested), which copies the data to the subfolder in cell "C4".

    Public Sub cmd_CopyPk2_By_Lewis()
    
      Dim a As Integer
      Dim iNumberOfFiles As Integer
      Dim b As String
      
      Dim sDestinationFolder As String
      Dim sFileName As String
      Dim sSourceFolder As String
      Dim sSubFolderName As String
      Dim sPathAndSubFolderName As String
      
      sSourceFolder = "C:\Users\Paul\Briefing Pack Selector\Pack Contents\"
      sDestinationFolder = "C:\Users\Paul\Briefing Pack Selector\Output\"
      
      'The following were debugging statement(s) used by Lewis (can be ignored or deleted)
    #Const Lewis = False
    #If Lewis Then
      sSourceFolder = ThisWorkbook.Path & "\"
      sDestinationFolder = ThisWorkbook.Path & "\"
    #End If
    
      Sheets("Briefing Pack 1").Select
      
      'Copy Source files to the 'Output Folder'
      iNumberOfFiles = Cells(Rows.Count, 1).End(xlUp).Row
      
      'The following were debugging statement(s) used by Lewis (can be ignored or deleted)
    #If Lewis Then
      iNumberOfFiles = 0 'START HERE
    #End If
    
      For a = 1 To iNumberOfFiles
        sFileName = Cells(a, 1)
        FileCopy sSourceFolder & sFileName, sDestinationFolder & sFileName
      Next a
      
      '**********************************************************
      'Option 1 - Create a New Subfolder if it is a complete name (path and file) in Cell 'C3'
      '**********************************************************
      
      'Get the Subfolder name  (including path)
      sPathAndSubFolderName = Sheets("Briefing Pack Selector").Range("C3").Text
      
      'Strip out leading and trailing spaces from the name
      sPathAndSubFolderName = Trim(sPathAndSubFolderName)
      
      'Make sure the name is NOT BLANK
      If Len(sPathAndSubFolderName) = 0 Then
        MsgBox "Terminating.  The contents of cell 'C3' is BLANK"
        'Exit (i.e. 'Exit Sub' or do some other kind of error processing)
      End If
      
      'Create the new SubFolder (if it doesn't already exist)
      If LJMFolderExists(sPathAndSubFolderName) = False Then
        MkDir sPathAndSubFolderName
      
        If LJMFolderExists(sPathAndSubFolderName) = False Then
          MsgBox "Error in creating Subfolder: " & vbCrLf & _
                 "Name: " & sPathAndSubFolderName
        End If
      End If
      
      
      '**********************************************************
      'Option 2 - Create a New Subfolder if it is not a completed path (.e.g. 'Archive')
      'that is a subfolder of 'C:\Users\Paul\Briefing Pack Selector\Output\'
      '**********************************************************
      
      'Create the Subfolder name
      '
      'NOTE: I arbitrarily chose 'C4' for this file name - for example purposes only
      sSubFolderName = Sheets("Briefing Pack Selector").Range("C4").Text
      
      'Strip out leading and trailing spaces from the name
      sPathAndSubFolderName = Trim(sPathAndSubFolderName)
      
      'Make sure the name is NOT BLANK
      If Len(sSubFolderName) = 0 Then
        MsgBox "Terminating.  The contents of cell 'C3' is BLANK"
        'Exit (i.e. 'Exit Sub' or do some other kind of error processing)
      End If
      
      'Create the complete Sub Folder path and file name
      'NOTE: 'sDestinationFolder' MUST have a trailing '\' (as it does in your case)
      sPathAndSubFolderName = sDestinationFolder & sSubFolderName
      
      'Create the new SubFolder (if it doesn't already exist)
      If LJMFolderExists(sPathAndSubFolderName) = False Then
        MkDir sPathAndSubFolderName
      
        If LJMFolderExists(sPathAndSubFolderName) = False Then
          MsgBox "Error in creating Subfolder: " & vbCrLf & _
                 "Name: " & sPathAndSubFolderName
        End If
      End If
      
      MsgBox "Files have been copied to output folder"
      
      'Put the files into the SubFolder From 'C4'
      sSourceFolder = "C:\Users\Paul\Briefing Pack Selector\Pack Contents\"
      sDestinationFolder = sPathAndSubFolderName & "\"
        
      For a = 1 To iNumberOfFiles
        sFileName = Cells(a, 1)
        FileCopy sSourceFolder & sFileName, sDestinationFolder & sFileName
      Next a
      
      MsgBox "Files have been copied to the SubFolder. Folder Name:" & vbCrLf & _
             sDestinationFolder
      
      Sheets("Briefing Pack Selector").Select
    End Sub
    
     
    Public Function LJMFolderExists(sPathAndFullFileName As String) As Boolean
      'This returns TRUE if a folder exists and FALSE if a folder does NOT exist
      'This will return FALSE if the 'sPathAndFullFileName' is a file
      
      Dim iFileAttributes As Integer
    
      On Error Resume Next
      iFileAttributes = GetAttr(sPathAndFullFileName)
      iFileAttributes = iFileAttributes And vbDirectory
      On Error GoTo 0
         
      LJMFolderExists = False
      If iFileAttributes = vbDirectory Then
        LJMFolderExists = True
      End If
      
    End Function

  13. #13
    Registered User
    Join Date
    01-26-2014
    Location
    Chorley, England
    MS-Off Ver
    Excel 2003
    Posts
    8
    Thanks Lewis! We have a winner. The files are still copying to the "...\output" folder as well as the created one but I can live with that.

    Your help has really been appreciated

    Best regards

    Paul

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Dashboard creation needed
    By ukphoenix in forum Excel General
    Replies: 8
    Last Post: 05-14-2013, 04:59 AM
  2. Automaticaly open folder needed
    By Nico180 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-08-2013, 08:19 AM
  3. Macro For folder Creation In Outlook 2007
    By nuttycongo123 in forum Outlook Programming / VBA / Macros
    Replies: 10
    Last Post: 03-06-2011, 03:37 AM
  4. Folder Creation with Subfolders of the same each time?
    By ccomito1223 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-16-2010, 12:26 PM
  5. Folder Creation with a Macro
    By dcgrove in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-13-2008, 02:30 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1