工作表拆分后保持源格式

时间:2018-08-23 13:33:18

标签: excel vba format

请有人告诉我如何保留使用下面的宏创建的文件的源格式。当我打开新文件时,颜色与原始文件相比都发生了变化,我需要匹配它们。

Sub SaveSheets()

    ' Save sheets as seperate workbooks
    ' Keyboard Shortcut: Ctrl+Shift+W

    Dim wbDest As Workbook
    Dim wbSource As Workbook
    Dim sht As Object    'Could be chart, worksheet, Excel 4.0 macro,etc.
    Dim strSavePath As String

    On Error GoTo ErrorHandler

    Application.ScreenUpdating = False    'Don't show any screen movement

    strSavePath = "C:\Users\Joe Bloggs\Documents\Save Sheets\" 'Change this to suit your needs

    Set wbSource = ActiveWorkbook

    For Each sht In wbSource.Sheets
        sht.Copy
        Set wbDest = ActiveWorkbook
        wbDest.SaveAs (strSavePath & sht.Name)
        wbDest.Close    'Remove this if you don't want each book closed after saving.
    Next

    Application.ScreenUpdating = True

    Exit Sub

ErrorHandler:    'Just in case something hideous happens
    MsgBox "An error has occurred. Error number=" & Err.Number & ". Error description=" & Err.Description & "."

End Sub

0 个答案:

没有答案