阻止用户停止宏(Excel VBA)

时间:2015-08-19 15:59:12

标签: excel vba excel-vba

我想阻止用户在保存期间停止宏。 我找到了以下代码:

Application.EnableCancelKey = xlDisabled

如果你按一下 ESC 键就可以了,但是如果按住键很长一段时间就可以停止宏。

我尝试Application.EnableCancelKey = xlErrorHandler如下:

Application.EnableCancelKey = xlErrorHandler
On Error GoTo errHandler:

ActiveWorkbook.Save

exitHere:
  Exit Sub

errHandler:
  msgbox"something"
  Resume exitHere

有时它完美无缺,但有时如果我在完美时刻点击 ESC 键并持续几秒钟,我就可以停止宏。

你知道是否有办法让 ESC 键无效?

1 个答案:

答案 0 :(得分:0)

我从来没有这样做,但这就是我从你的代码开始的方式:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div id="wrapper">
  <div class="container">
    <div class="row">
      <div class="col-sm-4">
        <div class="panel panel-default">
          <div class="panel-heading panel-primary">Iphone 6</div>
          <div class="panel-body">
            <img src="http://store.storeimages.cdn-apple.com/4711/as-images.apple.com/is/image/AppleInc/aos/published/images/i/ph/iphone6/plus/iphone6-plus-box-gold-2014?wid=478&hei=595&fmt=jpeg&qlt=95&op_sharpen=0&resMode=bicub&op_usm=0.5,0.5,0,0&iccEmbed=0&layer=comp&.v=1411520675923"
            class="img-responsive" />
          </div>
        </div>
      </div>
      <div class="col-sm-4">
        <div class="panel panel-default">
          <div class="panel-heading panel-primary">Iphone 6</div>
          <div class="panel-body">
            <img src="http://store.storeimages.cdn-apple.com/4711/as-images.apple.com/is/image/AppleInc/aos/published/images/i/ph/iphone6/plus/iphone6-plus-box-gold-2014?wid=478&hei=595&fmt=jpeg&qlt=95&op_sharpen=0&resMode=bicub&op_usm=0.5,0.5,0,0&iccEmbed=0&layer=comp&.v=1411520675923"
            class="img-responsive" />
          </div>
        </div>
      </div>
      <div class="col-sm-4">
        <div class="panel panel-default">
          <div class="panel-heading panel-primary">Iphone 6</div>
          <div class="panel-body">
            <img src="http://store.storeimages.cdn-apple.com/4711/as-images.apple.com/is/image/AppleInc/aos/published/images/i/ph/iphone6/plus/iphone6-plus-box-gold-2014?wid=478&hei=595&fmt=jpeg&qlt=95&op_sharpen=0&resMode=bicub&op_usm=0.5,0.5,0,0&iccEmbed=0&layer=comp&.v=1411520675923"
            class="img-responsive" />
          </div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-sm-4">
        <div class="panel panel-default">
          <div class="panel-heading panel-primary">Iphone 6</div>
          <div class="panel-body">
            <img src="http://store.storeimages.cdn-apple.com/4711/as-images.apple.com/is/image/AppleInc/aos/published/images/i/ph/iphone6/plus/iphone6-plus-box-gold-2014?wid=478&hei=595&fmt=jpeg&qlt=95&op_sharpen=0&resMode=bicub&op_usm=0.5,0.5,0,0&iccEmbed=0&layer=comp&.v=1411520675923"
            class="img-responsive" />
          </div>
        </div>
      </div>
      <div class="col-sm-4">
        <div class="panel panel-default">
          <div class="panel-heading panel-primary">Iphone 6</div>
          <div class="panel-body">
            <img src="http://store.storeimages.cdn-apple.com/4711/as-images.apple.com/is/image/AppleInc/aos/published/images/i/ph/iphone6/plus/iphone6-plus-box-gold-2014?wid=478&hei=595&fmt=jpeg&qlt=95&op_sharpen=0&resMode=bicub&op_usm=0.5,0.5,0,0&iccEmbed=0&layer=comp&.v=1411520675923"
            class="img-responsive" />
          </div>
        </div>
      </div>
      <div class="col-sm-4">
        <div class="panel panel-default">
          <div class="panel-heading panel-primary">Iphone 6</div>
          <div class="panel-body">
            <img src="http://store.storeimages.cdn-apple.com/4711/as-images.apple.com/is/image/AppleInc/aos/published/images/i/ph/iphone6/plus/iphone6-plus-box-gold-2014?wid=478&hei=595&fmt=jpeg&qlt=95&op_sharpen=0&resMode=bicub&op_usm=0.5,0.5,0,0&iccEmbed=0&layer=comp&.v=1411520675923"
            class="img-responsive" />
          </div>
        </div>
      </div>
    </div>
  </div>
</div>