【问题标题】:excel vba byref type mismatchexcel vba byref类型不匹配
【发布时间】:2015-04-28 02:17:03
【问题描述】:

我正在尝试将 wb_ 和 ws_variables 传递给下面的函数 getinfofromclosedfile,我不断得到 wb_name 变量的 byref 参数不匹配。

 Sub check_update()

 Dim wb_path, wb_name, ws_name, ws_cell As String

 AGuser = GetUser
 If Dir("c:\users\" & AGuser & "\documents\appraiser_genie\genieold.xlsm") <> "" Then
    wb_path = "c:\users\" & AGuser & "\documents\"
    wb_name = "genieold.xlsm"
    ws_name = "input"
    ws_cell = Cells(17, 2).Address
    Sheets("input").Cells(17, 2).Select = GetInfoFromClosedFile(wb_path, wb_name, ws_name, ws_cell)
   End If
End Sub

Private Function GetInfoFromClosedFile(ByVal wbPath As String, _
    wbName As String, wsName As String, cellRef As String) As Variant

任何帮助将不胜感激!

【问题讨论】:

  • 在旁注中,这: Dim wb_path, wb_name, ws_name, ws_cell As String 不会像您认为的那样做,您需要像这样设置每个: Dim wb_path As String, wb_name作为字符串,ws_name 作为字符串,ws_cell 作为字符串
  • 如果你按照@DanDonoghue 的建议去做,你的原始代码应该可以工作。 :)

标签: excel byref vba


【解决方案1】:

ByVal关键字声明参数:ByVal wbName As String, ByVal wsName As String

Function GetInfoFromClosedFile(ByVal wbPath As String, ByVal wbName As String, ByVal wsName As String, cellRef As String) As Variant

【讨论】:

    【解决方案2】:

    https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/dim-statement

    声明多个变量 您可以在一个声明语句中声明多个变量,为每个变量指定变量名称,并在每个数组名称后面加上括号。多个变量用逗号分隔。 VB

    将 lastTime、nextTime、allTimes() 调暗为日期

    不确定 Dan Donoghue 是关于什么的,但您可以通过这种方式声明多个变量(参见上面的链接)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多