如题所述
首先要打开你需要的数个文件,而每个文件假设在VBA所在工作簿的 A列,从A1开始,并且文件名排列下去,中间没有空白单元格,直到空白的单元格结束。需要求和的是每个文件内的shee1的A2单元格,最后合计数在程序所在文件的b1单元格
public sub 遍历()
dim i as integer
dim sumnumber as long
dim filename as string
i = 1
do until cells(i,1)=“”
cells(i,1) = filename
workboos.open filename: = filename
Windows(filename).Activate
sumnumber = sumnumber + sheets("sheet1").range("a2")
activewindows.close
i = i+1
loop
sumnumber = range("b1")
end sub追问
public sub 遍历()
dim i as integer
dim sumnumber as long
dim filename as string
i = 1
do until cells(i,1)=“”
cells(i,1) = filename
workboos.open filename: = filename
Windows(filename).Activate
sumnumber = sumnumber + sheets("sheet1").range("a2")
activewindows.close
i = i+1
loop
sumnumber = range("b1")
end sub追问
怎么实现遍历的?求继续回答 有联系方式最好了
温馨提示:答案为网友推荐,仅供参考