2017-01-13 107 views
1

我使用此代碼刪除活動工作表,然後複製另一個工作表,然後將複製的工作表重命名爲與刪除的工作表相同,如何還可以更改複製的工作表選項卡顏色工作表匹配刪除的工作表。Excel VBA Store/Dim 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 

回答

4

使用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 
相關問題