0

在 Excel 2010 中,有人单击移动或复制到新工作簿后,我有一个要求,然后在新工作簿上运行以下语句:

Sub CSAColorFormattingSSRS2008()
      ActiveWorkbook.Colors = Workbooks("Book4").Colors
End Sub

问题是“Book4”是工作表来自的上一个工作簿,但这个工作簿名称可以更改。有没有办法通过更改您要复制的工作簿名称来做到这一点?我试图创建一个按钮来为每个人运行这个宏,但所有过去的书名总是不同的。

4

1 回答 1

1

您可以这样做,按钮为它们执行复制操作,然后设置颜色。

Option Explicit

Sub CopySetColor()
Dim strWkb As String, strSheet As String
strWkb = ThisWorkbook.Name
strSheet = ActiveSheet.Name

'get Workbook name to copy to -> ensure that only 2 workbooks are open, this and the one you want to copy to
Dim wkb As Workbook, wkbCopyTo As Workbook

For Each wkb In Workbooks

    If wkb.Name <> strWkb Then

        Set wkbCopyTo = wkb
        Exit For

    End If

Next

Sheets(strSheet).Copy Before:=wkbCopyTo.Sheets(1)

CSAColorFormattingSSRS2008 strWkb

End Sub

Sub CSAColorFormattingSSRS2008(strName As String)

      ActiveWorkbook.Colors = Workbooks(strName).Colors

End Sub
于 2013-02-07T20:05:35.140 回答