如何提示与输入框中输入用户的名字从sheet1
他们喜欢这个名字的表?如何允许用户输入工作表名称
回答
该代码会做..使用输入框
Sub renameSheet()
Dim NewName As String
NewName = InputBox("What Do you Want to Name the Sheet1 ?")
Sheets("Sheet1").Name = NewName
End Sub
喜欢这个。感谢 – 2014-09-29 07:41:06
+1简单伟大的答案;) – 2014-09-29 07:48:20
与不正确的名称可能可能遇到各种各样的难题 – whytheq 2014-09-29 11:33:17
试试这个代码:
Private Sub CommandButton1_Click()
Dim sheetname As String
sheetname = Me.TextBox1.Value
Sheets("Sheet1").Name = sheetname
End Sub
试试这个:(您可以分配例如快捷键,按ctrl + d来运行这个宏,而片是打开的)
Sub RenameSheet()
Dim strSheetName As String
strSheetName = InputBox("enter new name of Sheet", "Editing Sheet Name")
'With ThisWorkbook.Worksheets(1) 'use this if want to rename again and again and you know the sheet no = 1
'With ThisWorkbook.Worksheets("Sheet1") ' use this if want to rename once
With ThisWorkbook.ActiveSheet 'use this if want to rename any activesheet
.Name = strSheetName
End With
End Sub
参考:http://www.mrexcel.com/forum/excel-questions/538208-check-invalid-worksheet-name.html
此代码是强大的:
Sub TestSheetname()
Dim mySheetName$
mySheetName = InputBox("Enter proposed sheet name:", "Sheet name")
If mySheetName = "" Then
MsgBox "You did not enter anything or you hit Cancel.", 64, "No sheet name was entered."
Exit Sub
End If
'If the length of the entry is greater than 31 characters, disallow the entry.
If Len(mySheetName) > 31 Then
MsgBox "Worksheet tab names cannot be greater than 31 characters in length." & vbCrLf & _
"You entered " & mySheetName & ", which has " & Len(mySheetName) & " characters.", , "Keep it under 31 characters"
Exit Sub
End If
'Sheet tab names cannot contain the characters /, \, [, ], *, ?, or :.
'Verify that none of these characters are present in the cell's entry.
Dim IllegalCharacter(1 To 7) As String, i As Integer
IllegalCharacter(1) = "/"
IllegalCharacter(2) = "\"
IllegalCharacter(3) = "["
IllegalCharacter(4) = "]"
IllegalCharacter(5) = "*"
IllegalCharacter(6) = "?"
IllegalCharacter(7) = ":"
For i = 1 To 7
If InStr(mySheetName, (IllegalCharacter(i))) > 0 Then
MsgBox "You used a character that violates sheet naming rules." & vbCrLf & vbCrLf & _
"Please re-enter a sheet name without the ''" & IllegalCharacter(i) & "'' character.", 48, "Not a possible sheet name !!"
Exit Sub
End If
Next i
'Verify that the proposed sheet name does not already exist in the workbook.
Dim strSheetName As String, wks As Worksheet, bln As Boolean
strSheetName = Trim(mySheetName)
On Error Resume Next
Set wks = ActiveWorkbook.Worksheets(strSheetName)
On Error Resume Next
If Not wks Is Nothing Then
bln = True
Else
bln = False
Err.Clear
End If
'History is a reserved word, so a sheet cannot be named History.
If UCase(mySheetName) = "HISTORY" Then
MsgBox "A sheet cannot be named History, which is a reserved word.", 48, "Not allowed"
Exit Sub
End If
'If the worksheet name does not already exist, name the active sheet as the InputBox entry.
'Otherwise, advise the user that duplicate sheet names are not allowed.
If bln = False Then
Worksheets.Add.Name = strSheetName
MsgBox "A new sheet named ''" & mySheetName & "'' has been added.", 64, "Done"
Else
MsgBox "There is already a sheet named " & strSheetName & "." & vbCrLf & _
"Please enter a unique name for this sheet.", 16, "Duplicate sheet names not allowed."
End If
End Sub
好一个+1 :)。 – 2014-09-29 13:25:27
- 1. 如何允许用户输入java
- 2. 允许用户输入地点的名称而不是坐标
- 3. 如何防止JQuery中的空格并允许用户输入名称
- 4. 如何防止输入键提交表单,但仍然允许输入工作?
- 5. 允许客户端通过输入工作号码
- 6. python(空闲) - 表单给定名称,如何输入用户名
- 7. ComboBox不允许用户输入
- 8. 允许用户选择输入
- 9. 允许用户输入变量(Python)
- 10. 允许用户只输入文本?
- 11. 名称的用户输入
- 12. Python - 如何将用户输入用作数组名称?
- 13. Web配置允许用户不工作
- 14. 如何允许列表作为参数输入计划
- 15. 错误:在C++中不允许输入类型名称
- 16. 如何使Windows 8允许您在登录时输入用户名
- 17. 如何确保用户输入允许的枚举
- 18. 如何只允许用户输入数字
- 19. 如何在JOptionPane中允许来自用户的多个输入
- 20. 我如何确保用户只允许整数输入?
- 21. 如何不允许用户输入数字的文本框
- 22. 如何格式化用户输入以允许xx.xx格式
- 23. 如何让我的用户输入允许python中的变量?
- 24. 允许输入签名的.NETCF组件
- 25. 不允许用户输入管道字符'|'输入形式Angular
- 26. 允许用户跳过输入输入,只需按Enter键
- 27. 用户输入,不允许相同的输入两次
- 28. 不允许用户在输入中输入HTML标签
- 29. 如何清除SAPUI5输入字段只允许帮助输入值允许?
- 30. Rails安全性:允许斜杠作为用户输入
(有什么样的代码,你已经尝试过) – whytheq 2014-09-29 11:34:27