counter
स्मार्टक्यूए का लोगो

Copy content from multiple .xls files into one file and file name in last column

"copy content from multiple .xls files into one file and file name in last column" के लिए कोड उत्तर. हमें मिल 1 कोड उदाहरण पर स्मार्टक्यूए नीचे excel श्रेणी।

आपको जो समाधान चाहिए वह खोजें!

हम 50 से अधिक भाषाओं के सामान्य प्रोग्रामिंग मुद्दों के लिए समाधान प्रदान करते हैं, आशा है कि इससे मदद मिलेगी!

उदाहरण #1

द्वारा Excel Hero 2👍
Public Sub Fuji()
    Dim c&, sPath$, sFile$, v, wsReport As Worksheet
    On Error Resume Next
    sPath = "c:\tmp\fiji\"  '<-- Edit source file folder and INCLUDE final backslash.
    ActiveSheet.Copy
    Set wsReport = ActiveSheet
    wsReport.Name = "Merged"
    DoEvents
    sFile = Dir(sPath & "*.*")
    SetExcelEnvironment 1
    Do
        Application.StatusBar = "Processing... " & sPath & sFile
        With Workbooks.Open(sPath & sFile)
            With .Worksheets(1)
                v = .Range(.[a1], .Cells(.Rows.Count, "a").End(xlUp))
                With wsReport.Cells(.Rows.Count, "a").End(xlUp)(2).Resize(UBound(v))
                    .Value = v
                    .Offset(, 1) = sFile
                End With
            End With
            .Close 0
        End With
        sFile = Dir
    Loop Until sFile = ""
    With wsReport
        .Rows(1).Delete
        .Cells.EntireColumn.AutoFit
    End With
    SetExcelEnvironment 0
End Sub

Private Sub SetExcelEnvironment(bProcessing As Boolean)
    With Application
        .DisplayAlerts = Not bProcessing
        .ScreenUpdating = Not bProcessing
        .StatusBar = ""
        .DisplayStatusBar = bProcessing
    End With
End Sub
Public Sub Fuji()
    Dim c&, sPath$, sFile$, v, wsReport As Worksheet
    On Error Resume Next
    sPath = "c:\tmp\fiji\"  '<-- Edit this and INCLUDE final backslash.
    sFile = Dir(sPath & "*.*")
    ActiveSheet.Copy
    Set wsReport = ActiveSheet
    wsReport.Name = "Merged"
    DoEvents
    SetExcelEnvironment 1
    Do
        Application.StatusBar = "Processing... " & sPath & sFile
        With Workbooks.Open(sPath & sFile)
            With .Worksheets(1)
                v = .[a1].CurrentRegion.Resize(.Cells(.Rows.Count, "a").End(xlUp).Row)
                With wsReport.Cells(.Rows.Count, "a").End(xlUp)(2).Resize(UBound(v, 1), UBound(v, 2))
                    .Value = v
                    .Offset(, UBound(v, 2)).Resize(, 1) = sFile
                End With
            End With
            .Close 0
        End With
        sFile = Dir
    Loop Until sFile = ""
    With wsReport
        .Rows(1).Delete
        .Cells.EntireColumn.AutoFit
    End With
    SetExcelEnvironment 0
End Sub

Private Sub SetExcelEnvironment(bProcessing As Boolean)
    With Application
        .DisplayAlerts = Not bProcessing
        .ScreenUpdating = Not bProcessing
        .StatusBar = ""
        .DisplayStatusBar = bProcessing
    End With
End Sub
प्रश्न और उत्तर स्टैक ओवरफ़्लो से एकत्र किए जाते हैं, cc by-sa 2.5, cc by-sa 3.0 और cc by-sa 4.0 के तहत लाइसेंस प्राप्त होते हैं।

समान प्रश्न