【问题标题】:Need to assign user selected sheet name to variable需要将用户选择的工作表名称分配给变量
【发布时间】:2012-05-03 20:34:06
【问题描述】:

我想提示用户在工作表中选择一个单元格来填充一个值。我正在尝试使用Application.Input,但它没有获取在其中选择单元格的工作表的名称......它继续使用宏运行时处于活动状态的工作表名称。

我到处搜索。有没有办法将工作表名称以及用户在提示时选择的单元格范围分配给变量?

varCellContent = Application.InputBox(prompt:="Choose a sheet by clicking on any cell in it.", Type:=8)
strDestinationSheetName = ActiveSheet.Name
MsgBox ("Sheet = " & strDestinationSheetName)

【问题讨论】:

    标签: excel excel-2007 vba


    【解决方案1】:

    这是你正在尝试的吗?

    Option Explicit
    
    Sub Sample()
        Dim varCellContent As Range
        Dim strDestinationSheetName As String
    
        On Error Resume Next
        Set varCellContent = Application.InputBox(Prompt:="Choose a sheet by clicking on any cell in it.", Type:=8)
        On Error GoTo 0
    
        If Not varCellContent Is Nothing Then
            strDestinationSheetName = varCellContent.Parent.Name
    
            MsgBox ("Sheet = " & strDestinationSheetName)
        End If
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2021-09-13
      • 2015-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多