我们的项目中有一些代码看起来像这样:
Private Sub Method1()
Call InnerMethod
End Sub
Private Sub Method2()
InnerMethod
End Sub
Private Sub InnerMethod()
'' stuff
End Sub
Run Code Online (Sandbox Code Playgroud)
Method2优于Method2的优势是什么?
给出以下代码: 我似乎无法成功地将Range对象变量从一个子函数传递到另一个子函数.我花了整整一天时间研究和试验,然后才吞下骄傲来到这里.
请阅读下面的评论,并回答您有关为什么最后两行不会表现的任何想法.
Public Sub doSomethingToRows(ROI As Range)
*'do Something with the cell values within the supplied range*
End Sub
'
Public Sub testDoAltRows()
Dim RegionOfInterest As Range 'is this an object or not?
'*The following yields: Class doesn't support Automation (Error 430)*
'*Set RegionOfInterest = New Worksheet 'this just gives an error*
Set RegionOfInterest = Worksheets("Sheet1").Range("A1")
RegionOfInterest.Value = 1234.56 '*okay, updates cell A1*
Set RegionOfInterest = Worksheets("Sheet1").Range("B5:D15")
RegionOfInterest.Columns(2).Value = "~~~~~~" '*okay*
'doSomethingToRows (RegionOfInterest) 'why do I get …
Run Code Online (Sandbox Code Playgroud)