VBA:将不同工作簿中的某些工作表合并成一个工作簿 [英] VBA : Merge certain worksheets in different workbooks into one workbook

查看:409
本文介绍了VBA:将不同工作簿中的某些工作表合并成一个工作簿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个我无法解决的问题。这里是:



我想复制某些工作簿中包含的某些工作表,并将其全部粘贴到一个新的工作簿中。



更具体地说,我有一个名为«Fonds»的文件夹,其中包含20个工作簿,每个文件夹具有相同的结构:
它们都被称为01082014_FONDS,01082014更改每个工作簿,并且是一个月。
在每个这些工作簿中,都有一个名为投资组合的工作表,另一个名为Disponibilités的工作表。我想复制这两个工作表(还有其他的,但我只想复制那些),并将其粘贴到一个新的工作簿中。



最后,我有40张在单一的工作簿中,称为投资组合1,Disponibilités1,投资组合2,Disponibilités2...



任何人都可以帮助我吗?
非常感谢!

解决方案

您需要在VBA中执行以下操作:


  1. 循环访问文件夹中的文件使用VBA循环使用文件夹中的文件

  2. 查找Fonds是否在文件名中:检查字符串是否包含其他字符串

  3. 打开您找到的工作簿:设置wb = Workbooks.open(filename)

  4. 循环工作簿中的工作表:透过Excel表格

  5. 查找投资组合或Disponibilités在工作表的名称中:检查我fa字符串包含另一个字符串

  6. 重命名您找到的工作表: http://www.mrexcel.com/forum/excel-questions/72647-any-way-rename-sheet-visual- basic-applications.html

  7. 将工作表复制到当前工作簿:

  8. 关闭工作簿: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:

  1. Loop through files in a folder Loop through files in a folder using VBA?
  2. Find if the word "Fonds" is in the file name: Check if a string contains another string
  3. Open the workbook that you find: Set wb = Workbooks.open(filename)
  4. Loop through the worksheets in the workbook: Loop through Excel Sheets
  5. Find if the word "Portfolio" or "Disponibilités" is in the worksheet's name: Check if a string contains another string
  6. Rename the worksheet you find: http://www.mrexcel.com/forum/excel-questions/72647-any-way-rename-sheet-visual-basic-applications.html
  7. Copy the worksheet to the current workbook: Copy an entire worksheet to a new worksheet in Excel 2010
  8. Close the workbook: wb.close SaveChanges:=false

这篇关于VBA:将不同工作簿中的某些工作表合并成一个工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆