我创建了一个InputBox,它要求用户输入包含条目的最后一列的字母。根据索引,我希望标题是工作表名称。这是我写的代码:
Dim LastEntryCol As String
Dim ShtName As Variant
Set ShtName = ThisWorkbook.Sheets(2) '****The number 2 will need to be changed to an index. For now it's hard-entered.
LastEntryCol = Application.InputBox("What is the letter of the last column containing entry labels?", ShtName)`
当我运行它时,我收到错误1004“对象'_Application'的方法'InputBox'失败”。我怀疑它与我如何设置ShtName有关,因为如果我用“hooray coding!”之类的东西替换title参数,代码就会正常运行。
任何人都可以向我解释出现了什么问题以及如何解决这个问题?谢谢!
答案 0 :(得分:1)
您正在传递整个WorkSheet object
,而不仅仅是其名称。试试这个:
Dim LastEntryCol As String
Dim ShtName As String
ShtName = ThisWorkbook.Sheets(2).Name '****The number 2 will need to be changed to an index. For now it's hard-entered.
LastEntryCol = Application.InputBox("What is the letter of the last column containing entry labels?", ShtName)
答案 1 :(得分:0)
表格是一个集合,以便获得您需要使用的名称
ShtName = ThisWorkbook.Sheets.Item(2).Name
也很确定这将始终是一个字符串,因此您可以使用Dim ShtName As String
并避免设置。