VBA:将不同工作簿中的某些工作表合并成一个工作簿 [英] VBA : Merge certain worksheets in different workbooks into one workbook
问题描述
我想复制某些工作簿中包含的某些工作表,并将其全部粘贴到一个新的工作簿中。
更具体地说,我有一个名为«Fonds»的文件夹,其中包含20个工作簿,每个文件夹具有相同的结构:
它们都被称为01082014_FONDS,01082014更改每个工作簿,并且是一个月。
在每个这些工作簿中,都有一个名为投资组合的工作表,另一个名为Disponibilités的工作表。我想复制这两个工作表(还有其他的,但我只想复制那些),并将其粘贴到一个新的工作簿中。
最后,我有40张在单一的工作簿中,称为投资组合1,Disponibilités1,投资组合2,Disponibilités2...
任何人都可以帮助我吗?
非常感谢!
您需要在VBA中执行以下操作:
- 循环访问文件夹中的文件使用VBA循环使用文件夹中的文件
- 查找Fonds是否在文件名中:检查字符串是否包含其他字符串
- 打开您找到的工作簿:
设置wb = Workbooks.open(filename)
- 循环工作簿中的工作表:透过Excel表格
- 查找投资组合或Disponibilités在工作表的名称中:检查我fa字符串包含另一个字符串
- 重命名您找到的工作表: http://www.mrexcel.com/forum/excel-questions/72647-any-way-rename-sheet-visual- basic-applications.html
- 将工作表复制到当前工作簿:
- 关闭工作簿:code> wb.close SaveChanges:= false
I encounter a problem that I can’t solve. Here it is :
I want to copy certain worksheets contained in certain workbooks and paste it all in a single new workbook.
More specifically, I have a Folder called « Fonds » which contain 20 workbooks, each one having the same structure : They are all called « 01082014_FONDS », 01082014 changing for each workbook and being a day of the month. In each of those workbooks, there is a worksheet called « Portfolio » and another one called « Disponibilités ». I wanna copy those 2 worksheets (there are others but I want to copy only those ones) and paste it in a new workbook.
A the end, I have 40 sheets in a single workbooks, called « Portfolio 1 », « Disponibilités 1 », « Portfolio 2 », « Disponibilités 2 »…
Anyone can help me on this ? Thank you very much !
You'll need to do the following in VBA:
- Loop through files in a folder Loop through files in a folder using VBA?
- Find if the word "Fonds" is in the file name: Check if a string contains another string
- Open the workbook that you find:
Set wb = Workbooks.open(filename)
- Loop through the worksheets in the workbook: Loop through Excel Sheets
- Find if the word "Portfolio" or "Disponibilités" is in the worksheet's name: Check if a string contains another string
- Rename the worksheet you find: http://www.mrexcel.com/forum/excel-questions/72647-any-way-rename-sheet-visual-basic-applications.html
- Copy the worksheet to the current workbook: Copy an entire worksheet to a new worksheet in Excel 2010
- Close the workbook:
wb.close SaveChanges:=false
这篇关于VBA:将不同工作簿中的某些工作表合并成一个工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!