2016-12-14 110 views
1

我使用下面的代碼複製我的Excel表(它會彈出一個對話框詢問用戶他們想要多少次重複表)Excel中重命名工作表依次用VBA

Sub Create() 
'Updateby Extendoffice 20160704 
    Dim I As Long 
    Dim xNumber As Integer 
    Dim xName As String 
    Dim xActiveSheet As Worksheet 
    On Error Resume Next 
    Application.ScreenUpdating = False 
    Set xActiveSheet = ActiveSheet 
    xNumber = InputBox("Enter number of times to duplicate this sheet") 
    For I = 1 To xNumber 
     xName = ActiveSheet.Name 
     xActiveSheet.Copy After:=ActiveWorkbook.Sheets(xName) 
     ActiveSheet.Name = "dd-mm-yy" & I 
    Next 
    xActiveSheet.Activate 
    Application.ScreenUpdating = True 
End Sub 

我想excel VBA連續重命名工作表

要複製的工作表將始終是月份「01-01-17」的開始,因此我希望每個工作表都相應地重命名爲「02-01-17,03 -01-17等「

回答

2

MSDN DateSerial Function (Visual Basic):返回日期值代表在指定的年份,月份和日期中,將時間信息設置爲午夜(00:00:00)。

ActiveSheet.Name = Format(DateSerial(2017,I,1), "dd-mm-yy") 
相關問題