0

我有下面的代码在工作预算模板中工作。但是,在向所有用户推广之前,我需要让它对 Mac 友好。由于 Mac 不喜欢 ActiveX 控件,因此我试图找出一种方法来使此代码使用表单控件工作。有人对我有什么想法吗?谢谢!

Private Sub travelcalc_Click()
ActiveSheet.Unprotect Password:="PASSWORD"
    If Me.travelcalc.Value = False Then
    Range("C19:L20").Locked = False
    Sheets("Travel Calculator").Visible = False
Else
    Sheets("Travel Calculator").Visible = True
    Range("$C$19") = Worksheets("Travel Calculator").Range("$N$25")
    Range("$D$19") = Worksheets("Travel Calculator").Range("$P$25")
    Range("$E$19") = Worksheets("Travel Calculator").Range("$R$25")
    Range("$F$19") = Worksheets("Travel Calculator").Range("$T$25")
    Range("$G$19") = Worksheets("Travel Calculator").Range("$V$25")
    Range("$H$19") = Worksheets("Travel Calculator").Range("$X$25")
    Range("$I$19") = Worksheets("Travel Calculator").Range("$Z$25")
    Range("$J$19") = Worksheets("Travel Calculator").Range("$AB$25")
    Range("$K$19") = Worksheets("Travel Calculator").Range("$AD$25")
    Range("$L$19") = Worksheets("Travel Calculator").Range("$AF$25")
    Range("$C$20") = Worksheets("Travel Calculator").Range("$N$51")
    Range("$D$20") = Worksheets("Travel Calculator").Range("$P$51")
    Range("$E$20") = Worksheets("Travel Calculator").Range("$R$51")
    Range("$F$20") = Worksheets("Travel Calculator").Range("$T$51")
    Range("$G$20") = Worksheets("Travel Calculator").Range("$V$51")
    Range("$H$20") = Worksheets("Travel Calculator").Range("$X$51")
    Range("$I$20") = Worksheets("Travel Calculator").Range("$Z$51")
    Range("$J$20") = Worksheets("Travel Calculator").Range("$AB$51")
    Range("$K$20") = Worksheets("Travel Calculator").Range("$AD$51")
    Range("$L$20") = Worksheets("Travel Calculator").Range("$AF$51")
    Range("C19:L20").Locked = True
End If
ActiveSheet.Protect Password:="PASSWORD", AllowFormattingColumns:=True, AllowFormattingRows:=True

End Sub
4

2 回答 2

1

插入表单控件后,右键单击它,然后选择分配宏,然后选择新建。一个宏将被分配给它的“点击事件”。

检查它是否已被检查有点棘手,但可行:

Private Sub CheckBox1_Click() 'assign this macro to your checkbox; make sure it is in a standard module
ActiveSheet.Unprotect Password:="PASSWORD"

If ActiveSheet.Shapes("Check Box 1").OLEFormat.Object.Value <> 1 Then
  Range("C19:L20").Locked = False
  Sheets("Travel Calculator").Visible = False
Else
  yadda-yadda your code here...
End if

ActiveSheet.Protect Password:="PASSWORD", AllowFormattingColumns:=True, AllowFormattingRows:=True
End Sub

老实说,我只能希望这适用于 MAC,从未尝试过。但是,如果您说表单控件可以正常工作,那么这应该可以...

于 2015-05-11T17:08:46.800 回答
0

分配给复选框的这个宏运行良好。

Sub CheckBox11_Click()
ActiveSheet.Unprotect Password:="PASSWORD"
    If ActiveSheet.Shapes("Check Box 11").OLEFormat.Object.Value <> 1 Then
    Range("C19:L20").Locked = False
        Sheets("Travel Calculator").Visible = False
Else
    Sheets("Travel Calculator").Visible = True
    Range("$C$19") = Worksheets("Travel Calculator").Range("$N$25")
    Range("$D$19") = Worksheets("Travel Calculator").Range("$P$25")
    Range("$E$19") = Worksheets("Travel Calculator").Range("$R$25")
    Range("$F$19") = Worksheets("Travel Calculator").Range("$T$25")
    Range("$G$19") = Worksheets("Travel Calculator").Range("$V$25")
    Range("$H$19") = Worksheets("Travel Calculator").Range("$X$25")
    Range("$I$19") = Worksheets("Travel Calculator").Range("$Z$25")
    Range("$J$19") = Worksheets("Travel Calculator").Range("$AB$25")
    Range("$K$19") = Worksheets("Travel Calculator").Range("$AD$25")
    Range("$L$19") = Worksheets("Travel Calculator").Range("$AF$25")
    Range("$C$20") = Worksheets("Travel Calculator").Range("$N$51")
    Range("$D$20") = Worksheets("Travel Calculator").Range("$P$51")
    Range("$E$20") = Worksheets("Travel Calculator").Range("$R$51")
    Range("$F$20") = Worksheets("Travel Calculator").Range("$T$51")
    Range("$G$20") = Worksheets("Travel Calculator").Range("$V$51")
    Range("$H$20") = Worksheets("Travel Calculator").Range("$X$51")
    Range("$I$20") = Worksheets("Travel Calculator").Range("$Z$51")
    Range("$J$20") = Worksheets("Travel Calculator").Range("$AB$51")
    Range("$K$20") = Worksheets("Travel Calculator").Range("$AD$51")
    Range("$L$20") = Worksheets("Travel Calculator").Range("$AF$51")
    Range("C19:L20").Locked = True
End If
ActiveSheet.Protect Password:="PASSWORD", AllowFormattingColumns:=True, AllowFormattingRows:=True

End Sub
于 2015-05-11T18:33:55.860 回答