none
VBA - Active Workbook Path Folder - Duplicate Files Contained Within RRS feed

  • Question

  • Hi friends,

     

    I am trying to duplicate some files in my active workbook directory, I have got started and it was working ok untill  - I tried to change the file paths :(

     
    Sub DuplicateFilesinFolder()
    
    
    
        Dim fn As String
        Const myDir As String = "C:\Users\Dan\Desktop\a\"         'Folder
        Const newFolder As String = "C:\Users\Dan\Desktop\a\"     ' Target Folder to Output to
        
        
        
       ' --   Now trying to set as Active Workbook Folder
    '   Dim myDir As String
    '   Dim newFolder As String
    '
    '   myDir = ActiveWorkbook.path
    '   newFolder = ActiveWorkbook.path
    
    
        
        
        fn = Dir(myDir & "Set1*.txt")
        
        
        '--- Duplicate file
        
        Do While fn <> ""
    
            FileCopy myDir & fn, newFolder & Replace(fn, "Set1", "Set2")
            fn = Dir
        Loop
    
    End Sub

     

    This is meant to duplicate the files that are called Set1

    Rename the Set1 - to  Set2

     

    How can I set it to Active workbook path folder now, that is the current workbook folder.

     

    I followed the vba docs  - but no luck in setting the path yet 


    Cheers Dan :)

    Saturday, January 7, 2017 2:35 PM

Answers

  • Your paths need a backslash \ at the end, so use

        myDir = ActiveWorkbook.Path & "\"

    etc.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Dan_CS Saturday, January 7, 2017 8:13 PM
    Saturday, January 7, 2017 7:51 PM

All replies

  • Your paths need a backslash \ at the end, so use

        myDir = ActiveWorkbook.Path & "\"

    etc.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Dan_CS Saturday, January 7, 2017 8:13 PM
    Saturday, January 7, 2017 7:51 PM
  • Hello Hans,

    I have selective sight - I've seen it plenty of times before but it still evaded me

     

    And I've been looking everywhere for this  oh doh me!

    :)

     

    Well that’s solved

     

    Thank you

     

    Have a good weekend!


    Cheers Dan :)

    Saturday, January 7, 2017 8:13 PM