Excel summary of many excel files data into one report excel

前端 未结 2 1979
傲寒
傲寒 2021-01-25 05:56

I have a number of excel files containing filled survery, now I would like to have one master document that would have summary result of each.

Thus I imaging to have for

2条回答
  •  暖寄归人
    2021-01-25 06:44

    Those are at least 4 questions in one, let's see what we can do about it :-)

    First, there is no need to create another Excel instance, just add your code into an empty workbook (or into your master document, if that's ok for you)

     Public Function OpenWorkbook(mypath As String) As Workbook
         Workbooks.Open Filename:=mypath
         Set OpenWorkbook = ActiveWorkbook
     End Function
    

    Usage:

     Dim wb as workbook, ws as worksheet
     set wb = OpenWorkbook("your path")
     set ws = wb.Sheets(1)
    

    Avoiding the 2nd Excel instance automatically solves your problem with any VBA macros in your survey documents - when you open another workbook from within a running macro like the way above, the user won't get any security warning. (By the way, do the survey documents have to contain any macros?)

    Copying data from that sheet into your workbook goes like this:

     ThisWorkbook.Sheets("Name of your sheet").Range("A1") = ws.Range("A1")
    

    Iterating through a bunch of Excel files in a folder is described, for example, here

    Hope that helps.

提交回复
热议问题