命名多张纸
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了命名多张纸相关的知识,希望对你有一定的参考价值。
我有一个工作簿,里面有两个工作表,我把它们复制到工作簿的最后。
我试图通过一个InputBox给这两个工作表命名,并给它们两个不同的标准后缀,第一个是 "xxx - 项目",下一个是 "xxx - 报告"。
我已经将这两个工作表放在一个数组中。我如何通过InputBox引用这两个表?
Public Sub CopySheets()
Dim shName As String 'Sheet name var
Dim shExists As Boolean
Do
shName = InputBox("Please enter name of new project", "New Project")
If shName <> "" Then
shExists = SheetExists(shName) 'Check for existing sheet name
If Not shExists Then
Worksheets(Array(1, 2)).Copy After:=Sheets(Sheets.Count)
Else
MsgBox "Project Name:" & Space(1) & shName & " already exists", vbOKOnly + vbCritical, "Deter"
End If
End If
Loop Until Not shExists Or shName = ""
End Sub
Private Function SheetExists(ByVal sheetName As String, _
Optional ByVal wb As Workbook)
If wb Is Nothing Then Set wb = ActiveWorkbook
On Error Resume Next
SheetExists = Not wb.Worksheets(sheetName) Is Nothing
End Function
示例图片。
答案
类似于在if条件下的东西
If Not shExists Then
Worksheets(Array(1, 2)).Copy After:=Sheets(Sheets.Count)
Dim ws As Worksheet
Set ws = Sheets(Sheets.Count - 1)
ws.Name = shName & "- project"
Set ws = Sheets(Sheets.Count)
ws.Name = shName & "- report"
Else
以上是关于命名多张纸的主要内容,如果未能解决你的问题,请参考以下文章