首页 > 解决方案 > 变量名不匹配但仍然有效

问题描述

我正在查看我工作中某人创建的文件,它具有以下内容:

Sub Inputs(zDOB As Date, zRetAge As Double, zRetDate As Date, zDOJ As Date, zEmployer As Double, zEmployee As Double, _
           zSalary() As Double, zInflation As Double, zFund As Double, zAVCRate As Double, zEvalDate As Date, zAVCFund As Double, _
           zCharge As Double, zFund2 As Double, zAVCFund2 As Double)

    zDOB = Range("B1")
    zRetAge = Range("B7")
    zRetDate = Range("B8")
    zDOJ = Range("B11")
    zEmployer = Range("B15")
    zEmployee = Range("B16")
    zSalary(0) = Range("B14")
    zInflation = Range("B19")
    zFund = Range("B20")
    zFund2 = Range("B20")
    zAVCRate = Range("B24")
    zAVCFund = Range("B27")
    zAVCFund2 = Range("B27")
    zEvalDate = Range("B6")
    zCharge = Range("J7")

End Sub

很公平,这是设置稍后使用的输入。

我的问题是再次调用此子时:

Call Module3.Inputs(xDOfB, xRetirementAge, xDateRetire, xDOJ, xEmployer, xEmployee, xSalary, _
                         xInflation, xFund, xAVC, xEvalDate, xAVCFund, xCharge, xFund2, xAVCFund2)

z 现在是 x,这有什么不同吗?这是如何运作的?

标签: excelvba

解决方案


如果要跨下标使用公共变量,则可能需要使用它们。

Public zDOB As Variant
Public zRetAte As Variant
Sub textSub()
    Call Inputs
End Sub
Sub Inputs()
    zDOB = Range("B1")
    zRetAge = Range("B7")
End Sub

推荐阅读