+ Reply to Thread
Results 1 to 5 of 5

take data from different workbooks and sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    02-15-2006
    Posts
    12

    take data from different workbooks and sheets

    Hi all,

    I would need help with following problem ... I have structure on disk where are folders with years, than subfolders with months and in each subfolder can be workbook with several sheets. I need to go thru all folders/subfolders/workbooks/sheets.

    To find folders/subfolders/workbooks is not the problem. Problem is to go thru all sheets and pick-up the value from each sheet.

    
    Function nazevsouboru(a As String) As String
        j = 0
        Do While Mid(a, Len(a) - j, 1) <> "\" And Mid(a, Len(a) - j, 1) <> "/"
            j = j + 1
        Loop
        nazevsouboru = Right(a, j)
    End Function
    
    
    
    
    Sub listfolders()
    
        Dim fs As Object
        Dim soubor, soubor_dod As Object
        Dim a As String
        Dim fl1, fl2, fl3, fl4, fl5, fl6, fl7 As Object
        Dim x As Long
        Dim n As Long
        Dim Text, Textline, datum As String
                        
        startfolder = Range("B6").Value
    
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set fl1 = fs.GetFolder(startfolder)
     
        i = 0
        For Each fl2 In fl1.SubFolders 
            Set fs = CreateObject("Scripting.FileSystemObject")
            Set fl3 = fs.GetFolder(fl2.path)
    
            For Each fl4 In fl3.SubFolders 
                If UCase(fl2.Name) <> "ARCHIV" Then
                    Set fl5 = fs.GetFolder(fl4.path)
                    For Each soubor In fl5.Files
                        If UCase(Mid(soubor.Name, 1, 5)) = "AKČNÍ" Or UCase(Mid(soubor.Name, 1, 5)) = "AKCNI" Or UCase(Mid(soubor.Name, 1, 2)) = "AP" Then
    
                            Range("A21").Offset(i, 0).Value = "=HYPERLINK(""" & fl2 & """,""" & fl2.Name & """)"   ' write years
                            Range("B21").Offset(i, 0).Value = "=HYPERLINK(""" & fl4 & """,""" & fl4.Name & """)"   ' write months
                            a = soubor
                            Range("C21").Offset(i, 0).Value = "=HYPERLINK(""" & soubor & """,""" & nazevsouboru(a) & """)"   ' write workbook
    
                            '========== DOESN'T WORK
                            For j = 2 To "founded workbook.sheets.count"  'not pick up data from 2 first sheets
                                      Range("D21").Offset(i, 0).Value = founded workbook.each sheet.Range("A5").Value
                                      Range("E21").Offset(i, 0).Value = founded workbook.each sheet.Range("C8").Value 'for example
                                      
    
    
    
                            Next j
                            '====================
    
                            i = i + 1                        
                       
                        End If
                    Next
                End If
            Next
            
        Next
    Thank You very much in advance for Your help.

    Greetings

    Martin
    Last edited by martyzeman; 05-09-2014 at 05:40 AM.

  2. #2
    Forum Contributor lancer102rus's Avatar
    Join Date
    04-02-2014
    Location
    Ufa
    MS-Off Ver
    Excel 2010, 2013
    Posts
    252

    Re: take data from different workbooks and sheets

    You have to open each file and go thru all sheets like this
    set WB = Workbooks.Open(...)
    For each iSh in WB.Sheets
    .....
    Next

  3. #3
    Registered User
    Join Date
    02-15-2006
    Posts
    12

    Re: take data from different workbooks and sheets

    Hi lancer102rus

    Yes that would be the way, I thought if it would be possible without opening of the other workbooks. Any idea?

  4. #4
    Forum Contributor lancer102rus's Avatar
    Join Date
    04-02-2014
    Location
    Ufa
    MS-Off Ver
    Excel 2010, 2013
    Posts
    252

    Re: take data from different workbooks and sheets

    You can do this only with ADO

      
       With New ADODB.Connection
        .Provider = "Microsoft.Jet.OLEDB.4.0"
        .ConnectionString = "Data Source=" & FULL_PATH_TO_FILE & ";Extended Properties=Excel 8.0;"
        .CursorLocation = adUseClient
        .Open
        With .OpenSchema(adSchemaTables)
          rs = .RecordCount
          ReDim Arr(1 To rs)
          For i = 1 To rs
            MsgBox Replace(.Fields("TABLE_NAME").Value, "$", "")
            .MoveNext
          Next
          .Close
        End With
        .Close
      End With

  5. #5
    Registered User
    Join Date
    02-15-2006
    Posts
    12

    Re: take data from different workbooks and sheets

    Thank You lancer102rus, I don't understand ADO, so I did it with opening each workbook. Thanks!

+ 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. Replies: 2
    Last Post: 11-29-2012, 04:56 AM
  2. Replies: 0
    Last Post: 11-29-2012, 04:50 AM
  3. [SOLVED] link data between sheets / workbooks
    By nighttrainrex in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-06-2012, 01:02 AM
  4. Comparing data between sheets/workbooks...
    By ProjectMASE in forum Excel General
    Replies: 1
    Last Post: 09-06-2008, 05:56 AM
  5. Data from multiple sheets and workbooks
    By Lupus in forum Excel General
    Replies: 3
    Last Post: 08-15-2006, 01:55 AM

Tags for this Thread

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