【问题标题】:Copy hidden Master sheet rename it and place it at end of workbook复制隐藏的主表重命名并将其放在工作簿的末尾
【发布时间】:2017-08-12 02:01:31
【问题描述】:

我正在尝试复制一个名为 Master 的隐藏页面。

当用户单击名为 start 的工作表中的按钮时,它将打开一个输入框。用户将输入新的工作表名称。新工作表将放置在名为 start 的工作表之后。用户可以根据需要输入任意数量的工作表,每张工作表都放在最后。输入框需要对无效条目进行错误检查,如果点击取消则结束总和。

以下是我所拥有的。它只是在开始后重命名工作表。它不会使用新名称创建新工作表。

Sub Button3_Click()
    Dim wb As Workbook: Set wb = ThisWorkbook
    Dim ws As Worksheet: Set ws = wb.Sheets("Master")
    Dim newws As Worksheet, sh As Worksheet, newname
    Dim query As Long, xst As Boolean, info As String

retry:
    xst = False
    newname = Application.InputBox("Enter Inmate Name and Number.", info, , , , , , 2)
    If newname = "False" Then Exit Sub
    For Each sh In wb.Sheets
        If sh.Name = newname Then
            xst = True: Exit For
        End If
    Next
    If Len(newname) = 0 Or xst = True Then
        info = "Sheet name is invalid. Please retry."
        GoTo retry
    End If
    ws.Copy after:=ws
    Set newws = ActiveSheet: newws.Name = sh
End Sub

【问题讨论】:

  • 看看这篇文章:stackoverflow.com/questions/7692274/… 正确命名新工作表后,您可以将其移动到 Excel 文件中所需的任何位置。
  • 谢谢,这行得通。我是新手,网络人不编程,所以这对我来说都是新的。再次感谢我会从你添加的内容中学习。

标签: excel vba


【解决方案1】:

这可能会!...

    Dim wb As Workbook: Set wb = ThisWorkbook
    Dim ws As Worksheet: Set ws = wb.Sheets("Master")
    Dim NewName As String: NewName = ""
    Dim sh As Worksheet

Retry:
    NewName = Application.InputBox("Enter Inmate Name and Number.", info, NewName, , , , , 2)
    If NewName = "False" Then Exit Sub 'user shoose 'Cancel'
    For Each sh In wb.Sheets
        If NewName = sh.Name Or NewName = "" Then
            MsgBox "Sheet name is invalid. Please retry."
            GoTo Retry
            End If
        Next sh
    ws.Copy After:=ws
    With wb.Sheets("Master (2)")
        .Visible = True
        .Activate
        .Name = NewName
        End With

【讨论】:

    【解决方案2】:

    更改最后三个。

    Application.ScreenUpdating = false
    ws.visible = xlSheetVisible
    ws.Copy after:=ws
    Set newws = ActiveSheet: newws.Name = sh
    ws.visible = xlsheethidden
    Application.ScreenUpdating = True
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2012-08-12
      • 2015-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-28
      • 2020-03-02
      相关资源
      最近更新 更多