Results 1 to 1 of 1

VBa code to open files from two different folders and work on them simultaneously

Threaded View

  1. #1
    Registered User
    Join Date
    03-19-2013
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2010
    Posts
    2

    VBa code to open files from two different folders and work on them simultaneously

    Hi All,
    I have a problem in VBA. I have Reports called 'Masters' in one folder and reports called 'CAR' in another. My problem is I need to open both the files from these two different path and work and close them. Next it has to open 2nd master file and 2nd CAR file and so on.
    I tried with this code but it is not working out...Any help is appreciated.

    Sub DoItNow()
    
    MasterPath = Cells(1, 1).Value
    CARPath = Cells(1, 2).Value
    
    
    Set MacroBook = ThisWorkbook
    
    Set MasterFSO = CreateObject("Scripting.filesystemobject")
    Set MasterFolderObj = MasterFSO.getfolder(MasterPath)
    
    Set CARFSO = CreateObject("Scripting.filesystemobject")
    Set CARFolderObj = CARFSO.getfolder(CARPath)
    
    For Each masterfileobj In MasterFolderObj.Files
    
    For Each CARfileobj In CARFolderObj.Files
    
    Set Masterfile = Workbooks.Open(fileobj.Path)
    
    Set CARFile = Workbooks.Open(CARfileobj.Path)
    
    
    ' Do some work here
    
    CARFile.Close False
    Masterfile.Close True
    
    Next CARfileobj
    Next masterfileobj ' macro is opening same file everytime. It has to open next master file in path.
    
    End Sub
    In the above code CARFile is looping perfectly fine but MasterFile is looping once only which is the main problem. Can any one edit this code or give me someother code(s) so that it saves my time and energy?
    Thank you very much in advance.
    You may contact me @ sharmarudra@gmail.com


    Thanks
    Last edited by arlu1201; 03-19-2013 at 10:32 AM. Reason: Use code tags in future.

Thread Information

Users Browsing this Thread

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

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