在Excel中创建删除线宏 [英] Creating Strikethrough Macro in Excel

查看:191
本文介绍了在Excel中创建删除线宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VBA的新手,我正在尝试制作一个简单的宏,可以突出显示一组单元格,点击一个按钮,并删除所选的卖出。之后,您可以再次选择该单元格,单击相同的按钮,并删除删除线。



我一直在寻找体面的文档,但尚未找到任何内容。 / p>

这是一些代码。



此外,我想知道VBA中最佳文档的位置。

  Sub strikeOut()

Selection.Font.Strikethrough = True

End Sub

我也需要帮助命令按钮。



谢谢。

解决方案

看起来你在正确的道路上。根据你的代码,我假设你已经有一个命令按钮创建。如果是这样的话:

  Sub strikeOut()
With Selection.Font
.Strikethrough = Not。 Strikethrough
End with
End Sub

创建一个命令按钮: p>


  • Excel 2003及更早版本

    • 打开 Visual Basic 工具栏,并激活控制工具箱按钮。另一个框/工具栏应该出现不同的控制选项。

    • 选择按钮选项,并将其放置在所需的位置。


  • Excel 2007及更高版本

    • 点击在开发者标签/功能区。

    • 选择插入并选择按钮并将其放置在所需的位置。


  • *以下步骤适用于此时所有版本。

    • 右键单击您的新按钮,然后选择属性为您的按钮提供名称/标题。


  • 再次右键单击并选择查看代码

  • ButtonName_Click() sub中,使用以下方法之一添加 strikeOut()调用:

    • Call strikeOut()


  • 或简单

    • strikeOut




    • 为了回答你的问题的第二部分,很难说出什么是最好的,但这里有一些可能有帮助的链接:



      Chip Pearson的网站

      MSDN

      OZgrid


      I'm a novice to VBA and I'm trying to make a simple macro where one can highlight a set of cells, click a button, and strikethrough the selected sells. After, you can select the cell again, click the same button, and remove the strikethrough.

      I have been looking for decent documentation but, have yet to find anything.

      Here's some code.

      Also, I would love to know where the best documentation is on VBA.

      Sub strikeOut()
      
      Selection.Font.Strikethrough = True
      
      End Sub
      

      I also need help with the command button.

      Thank you.

      解决方案

      It looks like you're on the right path. Based on your code, I'm assuming you already have a command button created. If so try this:

      Sub strikeOut()
          With Selection.Font
              .Strikethrough = Not .Strikethrough
          End With
      End Sub
      

      To create a command button:

      • Excel 2003 and earlier:
        • Open up the Visual Basic toolbar and activate the Control Toolbox button. Another box/toolbar should appear with different control options.
        • Select the Button option and place it in the desired location.
      • Excel 2007 and later:
        • Click on the Developer tab/ribbon.
        • Select Insert and select Button and place it in the desired location.
      • *The steps below apply to all versions from this point forward.
        • Right-click on your new button and select Properties to give your button a name/caption.
      • Right-click again and select View Code.
      • In the ButtonName_Click() sub, add the strikeOut() call using either:
        • Call strikeOut()
      • or simply
        • strikeOut

      To answer the second part of your question, it's hard to say what is the 'best' but here are some links that may help:

      Chip Pearson's site
      MSDN
      OZgrid

      这篇关于在Excel中创建删除线宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆