如何提示與輸入框中輸入用戶的名字從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