我有一个现有的宏,我想通过传递一个rng参数来使用,但是如果没有传递rng,则该宏会通过inputbox要求一个rng,但是我无法使该参数正常工作。
这是我所拥有的:
Sub Four_Hundred_Fourty_Four_Split_Sub(Optional urng)
' Tried (Optional urng As Range), but it didn't work, couldn't run sub without arg
If IsEmpty(urng) = False Then 'urng = Missing
Debug.Print urng
Set urng = Application.InputBox("Select a range", "Obtain Range Object", Type:=8)
End If
如何获得可选的rng参数以使用此方法?
在过程中使用可选参数时,需要使用IsMissing
:
Sub Four_Hundred_Fourty_Four_Split_Sub(Optional urng)
If IsMissing(urng) Then
Set urng = Application.InputBox("Select a range", "Obtain Range Object", Type:=8)
End If
End Sub
问候,
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句