我有28个电子表格,全部位于不同的文件夹中。每个电子表格都有一个平面列表,我需要提取一个文档并每4周更新一次。我正在努力使自己的代码满足以下要求;
预先感谢
答案 0 :(得分:0)
在电子表格的A列下方的单元格中,将源文件夹和文件的列表作为路径显示-也许是当前打开文件中的第二个?然后您的代码应该:
Sub Example
'set a pointer to A1 in second page
Dim r as range
set r = thisworkbook.worksheets(2).range("a1")
'loop down column A until you reach an empty cell
do until r = ""
'for each cell, open the workbook identified,
dim wb as workbook
set wb = workbooks.open(r,False,True) 'open workbooks, don't update links, read only
'grab your range
dim source as range
set source = wb.worksheets("TRIMP Load Data NEW").Range("Planned Load")
'copy it to your target at the next blank row
source.copy 'copy data
thisworkbook.sheets(1).range("a" & rows.count).end(xlup).offset(1,0).pastespecial xlpastevalues 'paste values
Application.cutcopymode = false 'prevent prompt after paste
'and close the source file
wb.close false
'move down to next row in your list
set r = r.offset(1,0)
'and ...
loop
end sub