尝试做我以前没有尝试过的事情,不知道从哪里开始。
AIM :添加新行并创建工作表时,如下面的代码所示;我希望将DELETE按钮添加到每个新行中,当按下该按钮时,请用户确认,然后删除该行并将关联的工作表移动到另一个工作簿(WorkBook_Archive.xlsm),并且其日期包含在原始工作表之前名称(具有唯一的标识符)。
Private Sub NewServer_Click()
Dim shtName As String, ws As Worksheet
Dim wsMASTER As Worksheet, wsTEMP As Worksheet, wsGENERAL As Worksheet
Dim shNAMES As Range, nmANCHOR As Range
Dim eRow As Long, wasVISIBLE As Boolean
Dim shANCHOR As Range
With ThisWorkbook
Set wsMASTER = .Sheets("Main")
Set wsTEMP = .Sheets("ServerTemplate")
Set nmANCHOR = wsMASTER.Range("E10:E" & Rows.Count).End(xlUp).Offset(1)
wasVISIBLE = (wsTEMP.Visible = xlSheetVisible)
If Not wasVISIBLE Then wsTEMP.Visible = xlSheetVisible
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.EnableEvents = False
End With
wsMASTER.Unprotect Password:="J786djh$"
Do
wsMASTER.Activate
shtName = Application.InputBox("Please Enter Name For New Server" & vbCrLf & vbCrLf & _
"Click Cancel To Quit", "Define Sheet Name", Type:=2)
If shtName = "False" Then Exit Sub
Set ws = Nothing
On Error Resume Next
Set ws = Sheets(shtName)
On Error GoTo 0
If ws Is Nothing Then Exit Do
MsgBox "Please try again, ensuring no spaces are used in the new server name.", vbExclamation, "Name Exists"
Loop
eRow = wsMASTER.Range("E" & Rows.Count).End(xlUp).Row + 1
wsMASTER.Cells(eRow, "E").Value = shtName
wsTEMP.Copy After:=Worksheets(Sheets.Count)
ActiveSheet.Name = shtName
Set shANCHOR = wsMASTER.Range("E" & Rows.Count).End(xlUp)
wsMASTER.Hyperlinks.Add anchor:=shANCHOR, Address:="", SubAddress:="'" & shtName & "'!A1", TextToDisplay:=shtName
For Each wsGENERAL In ThisWorkbook.Worksheets
If wsGENERAL.Name = "ServerTemplate(1)" Then
wsGENERAL.Delete
End If
Next wsGENERAL
wsMASTER.Activate
With Application
.ScreenUpdating = True
.DisplayAlerts = True
.EnableEvents = True
End With
wsMASTER.Protect Password:="J786djh$"
End With
If wasVISIBLE Then wsTEMP.Visible = xlSheetHidden Else: If Not wasVISIBLE Then wsTEMP.Visible = xlSheetHidden
End Sub
我假设按钮的位置很重要,出于此目的,按钮将从第10行开始位于 F列中。