编译文件夹中所有工作簿的数据

时间:2016-05-11 13:12:42

标签: database excel vba excel-vba

我有一个包含150多个时间表的文件夹,其格式完全相同,我希望在“主”工作簿中编译。也就是说,每个时间表需要4个单元格才能在主文件中复制:

Cell C4(日期) Cell B7(员工姓名) Cell I50(现场时间) 单元格H50(办公时间)

主工作簿必须如下所示:

[硕士课程:目标] [1]

简单地说:我需要一个宏来运行特定文件夹中的所有excel文件,并将信息复制到“主”工作簿。

我不是这方面的专家,但我可以处理一些初级宏。我真的需要这个,所以任何帮助表示赞赏!谢谢!

编辑:我找到了一个复制每个文件第二行的宏。这是一个起点,但我没有编辑它的技能......

 Sub ConFiles()

    Dim Wbname As String
    Dim Wb As Workbook
    Dim ws As Worksheet
    Dim ws1 As Worksheet
    Dim lngCalc As Long
    Dim lngrow As Long

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
        lngCalc = .CalculationState
        .Calculation = xlCalculationManual
    End With


   Set ws1 = ThisWorkbook.Sheets.Add
    'change folder path here
    FolderName = "J:\15-0023_Vauquelin\8.0 Phase-construction\FdT fictives"
    Wbname = Dir(FolderName & "\" & "*.xls*")

    'ThisWorkbook.Sheets(1).UsedRange.ClearContents
    Do While Len(Wbname) > 0
        Set Wb = Workbooks.Open(FolderName & "\" & Wbname)
        Set ws = Nothing
        On Error Resume Next
        'change sheet name here
        Set ws = Wb.Sheets("Heures")
        On Error GoTo 0
        If Not ws Is Nothing Then
        lngrow = lngrow + 1
        ws.Rows(2).Copy ws1.Cells(lngrow, "A")
        End If
        Wb.Close False
        Wbname = Dir
    Loop

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .Calculation = lngCalc
    End With
End Sub

1 个答案:

答案 0 :(得分:0)

select 
    ?[open_pos>0;open_price-open_wavgprice;open_wavgprice-open]
  from position_summary