【发布时间】:2014-04-30 16:15:00
【问题描述】:
我试图让 VBA 中的子调用另一个函数,该函数返回一个范围并设置为一个变量。尝试运行 GetInputs() 方法时出现语法错误。
Function GetDataRange(str As String) As Range
' This prompts the user to select a range of data, we will need to call this once for inputs and once for outputs
Dim rRange As Range
On Error Resume Next
Application.DisplayAlerts = False
Set rRange = Application.InputBox(Prompt:= _
str, _
Title:="SPECIFY RANGE", Type:=8)
On Error GoTo 0
Application.DisplayAlerts = True
If rRange Is Nothing Then
Exit Function
Else
rRange.Font.Bold = True
End If
GetDataRange = rRange
End Function
Sub GetInputs()
Dim rg As Range
Set rg = GetDataRange("Select Inputs:")
End Sub
编辑:我添加了这段代码:
Sub Test()
End Sub
当我尝试运行它时,我得到了相同的语法错误,突出显示了 Sub Test() 行。
【问题讨论】: