求助EXCEL使用VBA批量打开一系列表格文件并复制里面的数据到另一个表格文件中

2025-04-13 04:38:07
推荐回答(2个)
回答1:

这样的代码一般可以DIR扫描文件夹,或者指定文件名,例如:

'Dir 循环
set st=activesheet
p = "c:\数据\"
n = Dir(p & "*.xls?")
while n<>""
    with workbooks.open(p & n)
        activesheet.usedrange.copy st.rows(rows.count,1).end(xlup).offset(1,0)
        .close
    end with
    n=Dir
wend

或者:

'指定 循环 201901 ~ 201912
set st=activesheet
for n=1 to 12
    with workbooks.open("c:\数据\2019" & format(n,"") & ".xlsx")
        activesheet.usedrange.copy st.rows(rows.count,1).end(xlup).offset(1,0)
        .close
    end with
next n

回答2:

写代码可以实现的,发文件来