简体   繁体   English

将特定的工作表导出到多个工作簿

[英]Export Specific Sheets into Multiple workbooks

Really stuck with a macro I using at the moment. 我现在确实使用了一个宏。 What I have at the moment is a marco that exports every worksheet into a separate workbook which is great. 我现在所拥有的是一个marco,可以将每个工作表导出到一个单独的工作簿中,这很棒。

My issue is I have columns linked to a another worksheet (“Mapping”) for data validations. 我的问题是我有链接到另一个工作表(“映射”)的列以进行数据验证。

When I open the newly created workbooks the data validation links are all broken. 当我打开新创建的工作簿时,数据验证链接全部断开。

So I'm wondering is it possible to change this macro so when it exports each worksheet, it also exports the “Mapping” sheet into each of the newly created workbooks? 因此,我想知道是否可以更改此宏,以便在导出每个工作表时也将“映射”表导出到每个新创建的工作簿中? Code I'm currently using below: 我目前正在使用的代码如下:

 Option Explicit Dim MainWorkBook As Workbook Dim NewWorkBook As Workbook Sub ExportWorksheet() Dim Pointer As Long Set MainWorkBook = ActiveWorkbook Range("E2").Value = MainWorkBook.Sheets.Count Application.ScreenUpdating = False 'enhance the performance For Pointer = 2 To MainWorkBook.Sheets.Count Set NewWorkBook = Workbooks.Add MainWorkBook.Sheets(Pointer).Copy After:=NewWorkBook.Sheets(1) Application.DisplayAlerts = False NewWorkBook.Sheets(1).Delete Application.DisplayAlerts = True With NewWorkBook .SaveAs filename:="H:\\2017\\Macro\\" & MainWorkBook.Sheets(Pointer).Name & ".xlsx" 'you may change to yours End With NewWorkBook.Close SaveChanges:=True Next Pointer Application.ScreenUpdating = True Range("D5").Value = "" End Sub 

Having played around abit I think you can change 玩了几周之后,我想你可以改变

MainWorkBook.Sheets(Pointer).Copy After:=NewWorkBook.Sheets(1)

To

MainWorkBook.Sheets(Array(Pointer, "Mapping")).Copy After:=NewWorkBook.Sheets(1)

Which preserves the Data Validation 保留数据验证

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从所选工作簿的多个工作表中的特定区域获取数据 - Get data from specific areas in multiple sheets in selected workbooks 如何使用python从多个excel工作簿中堆叠特定工作表 - how to stack specific sheets from multiple excel workbooks using python 从文件夹中多个工作簿的特定 Excel 工作表导入数据 - Importing Data from specific excel sheets from multiple workbooks in a folder VBA代码遍历并编译来自多个工作簿的特定工作表 - VBA code to loop through and compile specific sheets from multiple workbooks 读取同一目录中的所有 Excel 工作簿,每个工作簿都有多个工作表,并将每个工作表导出为 R 中的 a.csv - Read all Excel workbooks in the same directory each with multiple sheets and export each sheet as a .csv in R 循环以在多个 Excel 工作簿中创建多个工作表 - Loop to create multiple sheets in multiple Excel workbooks 有没有一种方法可以从多个工作簿的特定工作表中提取数据并将其添加到现有工作簿中? - Is there a way to pull data from specific sheets from multiple workbooks and add them to an existing workbook? VBA 从多个工作簿复制所有工作表 - VBA to copy all sheets from multiple workbooks 合并多个工作簿中的特定工作表 - Merge particular sheets from multiple workbooks VBA:从多个工作簿/工作表中提取值 - VBA: Extract values from multiple Workbooks/sheets
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM