+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    02-25-2009
    Location
    bfn,rsa
    MS-Off Ver
    Excel 2003
    Posts
    17

    list from many workbooks and file open

    Dear sir / madam

    Can someone please help me?

    I’ve got a workbook named (“Summary”) and a folder named “Employee workbooks”.

    The workbooks in the “Employee Workbooks” folder are workbooks that my employees will be working on. I will be working on the “Summary” workbook.

    What I would like is a macro that will extract the data from cells (b2, b3, b4, e2, e3) from all the employee workbooks and list them in my “Summary” workbook below each other.

    Also a macro that when I click on an employee’s number in the list in my “Summary” workbook that employee’s workbook will automatically open.

    Thank you
    Attached Files Attached Files
    Last edited by wegkruip; 03-12-2010 at 08:20 AM.

  2. #2
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,228

    Re: list from many workbooks and file open

    Here's my stock macro adjusted for your scenario.
    Code:
    Option Explicit
    
    Sub Consolidate()
    'Author:     JBeaucaire'
    'Date:       3/11/2010     (2007 compatible)'
    'Summary:    Open all Excel files in a specific folder and merge data'
    '            into one master sheet (stacked)'
    '            creates hyperlink to each imported file'
    Dim fName As String, fPath As String, fPathDone As String, OldDir As String
    Dim LR As Long, NR As Long
    Dim wbkOld As Workbook, wbkNew As Workbook, ws As Worksheet
    
    'Setup'
        Application.ScreenUpdating = False
        Application.EnableEvents = False
        Application.DisplayAlerts = False
        
        Set wbkNew = ThisWorkbook
        wbkNew.Activate
        Sheets("Summary").Activate   'sheet report is built into'
        
        If MsgBox("Import new data to this report?", vbYesNo) = vbNo Then Exit Sub
        
        If MsgBox("Clear the old data first?", vbYesNo) = vbYes Then
            Range("A2:E" & Rows.Count).Clear
            NR = 2
        Else
            NR = Range("A" & Rows.Count).End(xlUp).Row + 1
        End If
    
    'Path and filename'
        OldDir = CurDir             'memorizes the current working path'
        fPath = "C:\Documents and Settings\Juanita du Preez\Desktop\Work\Employee Worksheets\"
        ChDir fPath
        fName = Dir("EMP*.xls")      'filtering key, change to suit'
    
    'Import a sheet from found file'
        Do While Len(fName) > 0
            'Open file'
                Set wbkOld = Workbooks.Open(fName)
            'copy data'
                With Sheets("Sheet1")
                    wbkNew.Sheets("Summary").Range("A" & NR) = .[B2]
                    wbkNew.Sheets("Summary").Range("B" & NR) = .[B3]
                    wbkNew.Sheets("Summary").Range("C" & NR) = .[B4]
                    wbkNew.Sheets("Summary").Range("D" & NR) = .[E2]
                    wbkNew.Sheets("Summary").Range("E" & NR) = .[E3]
                End With
            'close file'
                wbkOld.Close False
            'add hyperlink
                ActiveSheet.Hyperlinks.Add Anchor:=Range("A" & NR), Address:=fPath & fName, TextToDisplay:=Range("A" & NR).Text
            'Next row'
                NR = NR + 1
            'ready next filename'
                fName = Dir
        Loop
    
    'Cleanup'
        Application.DisplayAlerts = True
        Application.EnableEvents = True
        Application.ScreenUpdating = True
    
    'restores original working path'
        ChDir OldDir
    End Sub
    Attached Files Attached Files
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  3. #3
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,228

    Re: list from many workbooks and file open

    Thanks for the feedback, let me know how it works for you...
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

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.2.0