VBA宏Excel脚本应复制整个文件夹数据

时间:2013-10-08 08:45:13

标签: excel vba excel-vba

背景:约。 300个Excel调查(有多个工作表)应集中在一个单独的Excel中。宏已准备就绪。 目标:虽然宏已经准备好并且能够从Survey excel中复制所需的数据,但我无法一次复制所有300个调查(我必须在所有调查中逐一进行)

问题:是否可以要求宏从特定网络路径中定位副本,然后复制所有300个excel工作簿?

宏脚本:

Function bIsBookOpen(ByRef szBookName As String) As Boolean
    On Error Resume Next
    bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function

Sub Start()
currwb = ActiveWorkbook.Name

If bIsBookOpen("PERSONAL.XLSB") Then
    Windows("PERSONAL.XLSB").Visible = True
    ActiveWindow.Close
End If

If Workbooks.Count > 1 Then
MsgBox " To many files open...  " & Workbooks(1).Name
Else
Application.Dialogs(xlDialogOpen).Show
Response = MsgBox("Weiter mit 'IT-Personal'?", vbYesNo)
If Response = vbYes Then
Windows(currwb).Activate
Call CopyForm
End If

End If

End Sub

1 个答案:

答案 0 :(得分:1)

循环浏览文件夹中的文件

Sub LoopThroughFiles()
    Dim path As String
    Dim filename As String
    Dim wb As Workbook
    path = ""  'your folder path here
    filename = Dir(path & "*.xls")

    While (filename <> "")
        Set wb = Workbooks.Open(path & filename)
        'Your code goes here
        wb.Close
        filename = Dir
    Wend
End Sub