如何对同一文件夹下多个excel文件进行相同的宏操作

2025-03-13 02:45:10
推荐回答(2个)
回答1:

存放在同一文件夹下有点难,不如先放在另外一个文件夹

 Dim r&, Filename$, wb As Workbook, sht As Worksheet,  fn$
    Application.ScreenUpdating = False
    Filename = Dir(ThisWorkbook.Path & "\*.xlsx")
    Do While Filename <> ""
        If Filename <> ThisWorkbook.Name Then
            fn = ThisWorkbook.Path & "\" & Filename
            workbooks.open(fn)
            .
            .
            .
        End If
        Filename = Dir '取得其他工作簿名称
    Loop
    Application.ScreenUpdating = True

回答2:

dir ifile as string
ifile=dir("c:\123\*.xls")
while ifile<>""
调用宏A(ifile)
iffile=dir
wend