【问题标题】:Compile Error argument not optional on Mac only编译错误参数仅在 Mac 上不是可选的
【发布时间】:2020-08-03 17:07:48
【问题描述】:

我在 Windows 10 上的 Excel 2010 中有一个有效的 Excel 工作表,由于单击按钮时出现“参数不是可选”错误,我的客户端在 Excel 2011 for Mac 上失败了。此外,它无法在运行 Office 365 的另一台计算机上运行。 似乎在第 6 行代码中突出显示字符:

Sub Rectangle4_Click()

Dim xSelShp As Shape, xSelLst As Variant, I As Integer
Set xSelShp = ActiveSheet.Shapes(Application.Caller)
Set xLstBox = ActiveSheet.ListBox4

If xLstBox.Visible = False Then
    xLstBox.Visible = True
    xSelShp.TextFrame2.TextRange.Characters.Text = "SAVE"
Else
    xLstBox.Visible = False
    xSelShp.TextFrame2.TextRange.Characters.Text = "SELECT"
    For I = xLstBox.ListCount - 1 To 0 Step -1
        If xLstBox.Selected(I) = True Then
        xSelLst = xLstBox.List(I) & ";" & xSelLst
        End If
    Next I
    If xSelLst <> "" Then
        Range("R4") = Mid(xSelLst, 1, Len(xSelLst) - 1)
    Else
        Range("R4") = ""
    End If
End If
End Sub

它显示/隐藏的 ListBox 是一个 ActiveX ListBox。

我怀疑它是否相关,但工作表中有 40 个这样的矩形按钮,所有代码几乎相同,只是切换了 4 个引用。

谁能看到我在这里遗漏了什么?或者对此类代码的跨平台问题有所了解?

谢谢。

【问题讨论】:

  • ActiveX 列表框?
  • @TimWilliams 是的,抱歉我忘了提。
  • 我没有精简 ActiveX 控件在 Mac 上工作,虽然我没有要测试的。
  • 这可以解释很多!但我认为它适用于 Office 365,对吧?我也不需要测试自己,所以我在这里检查。
  • 另外,有没有人建议切换到表单控件是否更好?考虑到它在 PC 和 Mac 上的 365 都失败了,我真的很迷茫......

标签: excel vba macos compatibility


【解决方案1】:

如果有人遇到这种情况,Tim 似乎是正确的,ActiveX 控件在 Mac 上不起作用。但它们在 Office 365 中也不起作用。我将其切换为表单控件,并让一切在我的客户端上完美运行。我对过去的自己的建议是从一开始就使用表单控件,如果您正在处理要发送给其他人的内容,则不惜一切代价避免使用 ActiveX。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    相关资源
    最近更新 更多