如何在VBA中打开启用宏的Excel

时间:2018-10-16 02:27:42

标签: excel vba excel-vba

我的想法是我可以打开文件夹中的每个xls,浏览工作表,然后将其复制并粘贴到打开的工作表中。出于某种奇怪的原因,我的小伙子说找不到文件夹,并不断询问是否将其删除。谁能帮我解决问题

Option Explicit
Option Base 1

Sub OpenWorkbooks()
Dim w As Worksheet, i As Integer, j As Integer
Dim Folder As String, FileName As String
Dim aWB As Workbook, tWB As Workbook
Dim nr As Integer, nc As Integer
Dim S() As Integer, mx As Integer
Dim c As Variant
Dim example As Range
Set example = ThisWorkbook.Worksheets("Sheet1").Range("A1")
nr = 9
nc = 5
ReDim S(nr, nc)
Folder = "C:\Users\Dhruv\Desktop\macro"
FileName = Dir(Folder & "\*.xlsm")
Do
    Workbooks.Open Folder & "\" & FileName
    Set aWB = ActiveWorkbook
    For Each w In Worksheets
        For i = 1 To nr
            For j = 1 To nc
                 If w.Range("A1:D6").Cells(i, j) = "Time" Then
                    c = c + 1
                    example.Offset(i + c, j) = c
                 End If
            Next j
        Next i
    Next
    aWB.Close SaveChanges:=False
    FileName = Dir
Loop Until FileName = " "
End Sub

0 个答案:

没有答案