简体   繁体   English

Excel VBA Store / Dim工作表标签颜色

[英]Excel VBA Store/Dim sheet tab color

I use this code to delete the active sheet and then copy a different sheet then rename the copied sheet the same as the deleted sheet, How can I also change the sheet tab color on the copied sheet to match the deleted sheet. 我使用此代码删除活动工作表,然后复制另一个工作表,然后将复制的工作表重命名为与删除的工作表相同的方式。如何更改复制的工作表上的工作表标签颜色以匹配删除的工作表。

Dim ShtName As String
Dim ws As Worksheet
Application.DisplayAlerts = False

ShtName = ActiveSheet.NAme
ActiveSheet.Delete

Dim NewSht  As Worksheet

Master_Work_Order.Copy After:=ActiveSheet

Set NewSht = ActiveSheet

'set new copied sheet name to Previous ActiveSheet's name
NewSht.NAme = ShtName

Use Sheet.Tab.Color 使用Sheet.Tab.Color

Sub test()

    Dim ShtName As String
    Dim ws As Worksheet

    Dim oldTabColor

    Application.DisplayAlerts = False

    ShtName = ActiveSheet.Name

    '/ Store Old Tab Color

    oldTabColor = ActiveSheet.Tab.Color

    ActiveSheet.Delete

    Dim NewSht  As Worksheet

    Master_Work_Order.Copy After:=ActiveSheet

    Set NewSht = ActiveSheet

    'set new copied sheet name to Previous ActiveSheet's name
    NewSht.Name = ShtName


     NewSht.Tab.Color = oldTabColor


End Sub

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM