我如何编写一个函数来实现excel中的一系列工作表?我想要做的是检查是否已创建相同的工作表名称,如果有,我需要结束程序,如果没有,那么我需要将模板从模板工作表复制并粘贴到新表。
Private Sub Workbook_Open()
Dim Ldate As String
Dim Lweekday As Integer
Dim Newweek As String
Dim name As String
Ldate = Date
Worksheets(1).Range("A1").Value = Ldate
Lweekday = Weekday(Ldate)
If Lweekday = 4 Then
Newweek = DateAdd("d", 3, Ldate)
name = Month(Newweek) & "-" & Day(Newweek) & "-" & Year(Newweek)
Sheets.Add.name = name
Worksheets("Template").Select
Range("A1:U37").Copy Destination:=Sheets(name).Range("A1")
End If
End Sub
答案 0 :(得分:0)
您的意思是想要影响VBA中某个范围的名称吗?
如果是这样,以下是帮助您的基础:
Dim RgToName as Range
RgToName = "=" & SheetName & "!R" & StartRow & "C" & StartColumn & _
":R" & EndRow & "C" & EndColumn
ActiveWorkbook.Names.Add Name:=RangeName, RefersToR1C1:=RgToName