真的坚持我目前使用的宏。我现在所拥有的是一个将每个工作表导出到一个单独的工作簿中的marco,这很棒。
我的问题是我将列链接到另一个工作表(“Mapping”)以进行数据验证。
当我打开新创建的工作簿时,数据验证链接都会被破坏。
所以我想知道是否可以更改此宏,以便在导出每个工作表时,它还会将“映射”表导出到每个新创建的工作簿中?我目前使用的代码如下:
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
答案 0 :(得分:1)
玩过abit我认为你可以改变
MainWorkBook.Sheets(Pointer).Copy After:=NewWorkBook.Sheets(1)
要
MainWorkBook.Sheets(Array(Pointer, "Mapping")).Copy After:=NewWorkBook.Sheets(1)
保留数据验证